This article is a memorandum based on the following Udemy courses. Docker course taught by US AI developers from scratch
--When the docker run command gets long --When starting multiple containers at once
Check if docker-compose is included. (It was included when Docker was installed, but just in case)
$ $ docker-compose --version
docker-compose version 1.27.4, build 40524192
If you do not get the version information, please install it. Install Docker Compose
Prepare the build context. The configuration this time is as follows.
biuldcontext
project-name
∟ docker-compose.yml
∟ Dockerfile
∟Other
docker command example
$ docker build .
$ docker run -d -it -v /Users/yukokanai/work/docker/project-name:/project-name -p 8888:8888 {image} bash
$ docker exec -it {Container name}
Write this in docker-compose.yml
docker-compose.yml
version: '3'
services:
web:
build: . #Implemented from build
ports: #-p Port forwarding
- '8888:8888'
volumes: #-v host directory(.)The container directory(/project-name)Mount on
- '.:/project-name'
tty: true #-Allocate t tty.
stdin_open: true #-Open i STDIN.
Run
#Go to build context
$ cd project-name
#If there is no image, build and run(I want to use it as a web server-d)
$ docker-compose up -d
#If you do not want to use the cache image, do as follows
#$ docker-compose up --build -d
#Go inside the container(web is the service name written in yml)
$ docker-compose exec web bash
End
$ docker-compose down
sample
docker-compose.yml
version: '3'
volumes:
db-data:
services:
web:
build: .
ports:
- '3000:3000'
volumes:
- '.:/my_product-register'
environment:
- 'POSTGRES_PASSWORD=postgres'
tty: true
stdin_open: true
depends_on:
- db
links:
- db
db:
image: postgres
volumes:
- 'db-data:/var/lib/postgresql/data'
environment:
- 'POSTGRES_PASSWORD=postgres'
Recommended Posts