Docker multi-container interconnection problem (php, composer)

I have created a dockerFile and docker-compose.yml:

Dockerfile

FROM php:7
RUN apt-get update -y && apt-get install -y libmcrypt-dev openssl
RUN docker-php-ext-install pdo mcrypt mbstring
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /app
COPY . /app

CMD php artisan serve --host=0.0.0.0 --port=8000
EXPOSE 8000

docker-compose.yml

version: "3"
services:
  web:
    build:
        context: .
        dockerfile: ./Dockerfile
    ports:
        - 3021:8000
    volumes:
        - ./laravel-app:/app    

when I execute docker-compose up-- force-recreate-d , laravel app will execute correctly on 127.0.0.1 force-recreate 3021 .

I have seen a lot of docker-composer articles on the web advocating minimizing container, so I would like to ask whether there is any way to rewrite this docker-compose.yml? using the official image of php and composer

. < hr >

the following is my test:

version: "3"
            
services:
    php:
        image: php:7-fpm
        ports: 
          - "3021:8000"
        volumes:
            - ./laravel-app:/app
    composer:
        image: composer:latest
        volumes:
            - ./laravel-app:/app
        working_dir: /app
        command: ["install","php artisan serve --host=0.0.0.0"]
        depends_on:
            - php
        
        

after completing this docker-compose.yml, I run docker-compose up-- force-recreate-d , however, I did not get any information on 127.0.0.1 force-recreate 3021 .

I then ran docker-compose ps and docker-compose log , and found that container for composer was not started and had the following error information

Invalid argument php artisan serve --host=0.0.0.0. Use "composer require php artisan serve --host=0.0.0.0" instead to add packages to your composer.json. 

how do I modify the subscription?

Jul.09,2021

the basic image is built with the alpine image version when Dockerfile is built, and then split the composer build into a separate phase (multi-stage build).

< hr >

what I mean is that it doesn't make sense to keep container to a minimum, but it may cause bug or bottlenecks when network data is frequently in and out of the container. Moreover, the previous way of building services through Dockerfile + DockerCompose is good, so it is not necessary to write it all into docker-compose.yml. In addition, there is no need to install some things, such as the mbstring, basic image itself. It is recommended that you search the basic image on Docker Store (click Tag to see the build script), and then select the appropriate Tag.


< H1 > docker-compose interconnection problem, networks is required < / H1 > < H1 > I have created a lnmp environment docker-compose.yaml. You can click this to change it < / H1 >
version: '3'
services:
  nginx:
    hostname: nginx
    build:
      context: ./nginx
      dockerfile: Dockerfile
    ports:
      - 80:80
    networks:
      - lnmp
    volumes:
      - ./wwwroot:/usr/local/nginx/html

  php:
    hostname: php
    build:
      context: ./php
      dockerfile: Dockerfile
    networks:
      - lnmp
    volumes:
      - ./wwwroot:/usr/local/nginx/html

  mysql:
    hostname: mysql
    image: mysql:5.6
    ports:
      - 3306:3306
    networks:
      - lnmp
    volumes:
      - ./mysql/conf:/etc/mysql/conf.d
      - ./mysql/data:/var/lib/mysql
    command: --character-set-server=utf8
    environment:
      MYSQL_ROOT_PASSWORD: 123456
      MYSQL_DATABASE: admin
      MYSQL_USER: admin
      MYSQL_PASSWORD: admin123456

networks:
  lnmp: 
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e47db5-444a9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e47db5-444a9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?