[Milight Design In-house Study Session # 5] Read docker-compose.yml and Dockerfile line by line

Building the strongest Laravel development environment using Docker [new edition] --Qiita Let's take a look at what the docker-composer.yml and Dockerfile used in are doing line by line.

https://github.com/ucan-lab/docker-laravel

docker-compose.yml

version: "3.8" #① Specify the version to be used in docker file
volumes: #(2) A volume area is secured in the VM.
  db-store:
  php-fpm-socket:
services: #③ Each service is a container
  app: #④ Service name (you can add it arbitrarily)
    build: ./docker/php #⑤ I'm building with the docker file here
    volumes:
      - php-fpm-socket:/var/run/php-fpm #⑥ In the area of the VM body, inside the container/var/run/php-fpm is mounted
      - ../backend:/work/backend

  web:
    build: ./docker/nginx
    ports:
      - 80:80
    volumes:
      - php-fpm-socket:/var/run/php-fpm
      - ../backend:/work/backend

  db:
    build: ./docker/mysql
    volumes:
      - db-store:/var/lib/mysql
    ports:
      - 3306:3306

Create File Version 3 Reference | Docker Document How to write the file changes depending on the specification of this version

(2) There is a VM in Docker for mac and an area for mounting container data is secured. Data does not disappear even if the container is deleted by mounting it on the VM You can give it any name you like.

--Service

docker-compose ps
        Name                      Command               State                 Ports              
-------------------------------------------------------------------------------------------------
docker-laravel_app_1   docker-php-entrypoint php-fpm    Up      9000/tcp                         
docker-laravel_db_1    docker-entrypoint.sh mysqld      Up      0.0.0.0:3306->3306/tcp, 33060/tcp
docker-laravel_web_1   /docker-entrypoint.sh ngin ...   Up      0.0.0.0:80->80/tcp    

Dockerfile

MySQL

https://github.com/ucan-lab/docker-laravel/blob/master/infra/docker/mysql/Dockerfile

#① From dockerhub to mysql8.Getting 0 images
FROM mysql:8.0
#② LABEL is set
LABEL maintainer="ucan-lab <[email protected]>"

#(3) A value is added to the environment variable of the OS.
ENV TZ=UTC \ #Time zone
  #The environment variable specified by MYSQL is specified.
  MYSQL_DATABASE=laravel_local \
  MYSQL_USER=phper \
  MYSQL_PASSWORD=secret \
  MYSQL_ROOT_PASSWORD=secret

#④ The host file is copied to the container
COPY ./my.cnf /etc/my.cnf

-① Image is acquired from https://hub.docker.com/_/mysql -If you do not write: 8.0, you will get the latest version ――② There is an audience who writes the maintainer with label after From. ――③ If you pass the environment variable to the mysql image, the official image will set it for you. --It is described in ʻEnvironment Variables` of https://hub.docker.com/_/mysql -④ The left is the host and the right is the container path --Copying the file that exists on the host to the specified path of the container

build

13:01:24 ❯ docker build -t mysql_image .
Sending build context to Docker daemon   2.56kB
Step 1/4 : FROM mysql:8.0
 ---> 0d64f46acfd1
Step 2/4 : LABEL maintainer="ucan-lab <[email protected]>"
 ---> Using cache
 ---> ef5acb641867
Step 3/4 : ENV TZ=UTC   MYSQL_DATABASE=laravel_local   MYSQL_USER=phper   MYSQL_PASSWORD=secret   MYSQL_ROOT_PASSWORD=secret
 ---> Using cache
 ---> 3eb31d9f4c84
Step 4/4 : COPY ./my.cnf /etc/my.cnf
 ---> Using cache
 ---> c064e3fa414a
Successfully built c064e3fa414a
Successfully tagged mysql_image:latest

--If build is successful, docker image will be created

13:08:35 ❯ docker images                
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
mysql_image          latest              f9666eb795b6        8 seconds ago       544MB

--A container is created based on the image --Image cannot be erased if there is a container that uses image

Try launching the container

Try launching ubuntu on docker hub

13:08:43 ❯ docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
54ee1f796a1e: Pull complete 
f7bfea53ad12: Pull complete 
46d371e02073: Pull complete 
b66c17bbf772: Pull complete 
Digest: sha256:31dfb10d52ce76c5ca0aa19d10b3e6424b830729e32a89a7c6eee2cda2be67a5
Status: Downloaded newer image for ubuntu:latest
root@d9d9fe415292:/# exit
exit

--Delete container

$ docker rm <CONTAINER ID>

--Delete image

$ docker rmi <IMAGE ID>

Reference article

-List of Dockerfile notations that you might use often -Qiita -I tried to explain how to write docker-compose.yml --Qiita

Recommended Posts

[Milight Design In-house Study Session # 5] Read docker-compose.yml and Dockerfile line by line
[In-house study session] Java basics-Lambda expression and Stream API- (2017/07/13)
[In-house study session] Java exception handling (2017/04/26)