"Docker-compose"의 두 판 사이의 차이
1번째 줄: | 1번째 줄: | ||
+ | Compose는 다중 컨테이너 Docker 애플리케이션을 정의하고 실행하기 위한 도구입니다. | ||
+ | |||
== 네트워킹 == | == 네트워킹 == | ||
myapp이라는 디렉토리에 다음과 같은 docker-compse.yml이 있다면<syntaxhighlight lang="yaml"> | myapp이라는 디렉토리에 다음과 같은 docker-compse.yml이 있다면<syntaxhighlight lang="yaml"> | ||
69번째 줄: | 71번째 줄: | ||
- SHOW=true | - SHOW=true | ||
- SESSION_SECRET | - SESSION_SECRET | ||
− | </syntaxhighlight> | + | </syntaxhighlight> |
+ | |||
+ | == Command == | ||
+ | https://docs.docker.com/compose/reference/ | ||
+ | |||
+ | === up === | ||
+ | Create and start containers | ||
+ | |||
+ | === down === | ||
+ | Stop and remove containers, networks, images, and volumes | ||
+ | |||
+ | === start === | ||
+ | Start services | ||
+ | |||
+ | === stop === | ||
+ | Stop services | ||
+ | |||
+ | === exec === | ||
+ | Execute a command in a running container | ||
+ | |||
+ | === run === | ||
+ | Run a one-off (one-time) command | ||
+ | $ docker-compose run web bash | ||
+ | --rm Remove container after run. Ignored in detached mode. | ||
+ | |||
== 외부링크 == | == 외부링크 == | ||
https://docs.docker.com/compose/ | https://docs.docker.com/compose/ | ||
[[분류:Docker]] | [[분류:Docker]] |
2020년 10월 20일 (화) 03:35 판
Compose는 다중 컨테이너 Docker 애플리케이션을 정의하고 실행하기 위한 도구입니다.
목차
네트워킹
myapp이라는 디렉토리에 다음과 같은 docker-compse.yml이 있다면
version: "3"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
ports:
- "8001:5432"
docker-compose up 을 실행하면
- 'myapp_default'라는 네트워크가 생성된다.
- 'web'의 설정을 사용한 컨테이너가 생성되고, 'web'이란 이름으로 'myapp_default'에 연결된다.
- 'db'의 설정을 사용한 컨테이너가 생성되고, 'db'라는 이름으로 'myapp_default'에 연결된다.
각 컨테이너는 'web', 'db'라는 호스트 이름으로 찾을 수있고, 컨테이너의 아이피 주소를 얻을 수 있다. 가령 'web'의 어플리케이션 코드에서 URL'postgres://db:5432'로 접속해서 데이터베이스를 사용할 수 있다.
'HOST_PORT"와 "CONTAINER_PORT'와의 차이점에 유의하는게 중요하다. 위의 예에서 'db'의 'HOST_PORT'는 8001이고 컨테이너의 포트는 5432이다. 'HOST_PORT'가 정의되면 , 서비스는 외부에서 접속이 가능해진다.
'web'컨테이너에서, 'postgres://db:5432'로 접속할 수 있고, 호스트 머신에서 연결문자열은 'postgres://{DOCKER_IP}:8001'이다.
compose file
https://docs.docker.com/compose/compose-file/
version 3
links
Link to containers in another service. Either specify both the service name and a link alias ("SERVICE:ALIAS"), or just the service name.
web:
links:
- "db"
- "db:database"
- "redis"
ports
호스트(컴퓨터)에 노출할 포트
ports:
- "3000"
- "3000-3005"
- "8000:8000"
- "9090-9091:8080-8081"
- "49100:22"
- "127.0.0.1:8001:8001"
- "127.0.0.1:5000-5010:5000-5010"
- "6060:6060/udp"
- "12400-12500:1240"
expose
Expose ports without publishing them to the host machine - they’ll only be accessible to linked services. Only the internal port can be specified.
expose:
- "3000"
- "8000"
environment
environment:
RACK_ENV: development
SHOW: 'true'
SESSION_SECRET:
environment:
- RACK_ENV=development
- SHOW=true
- SESSION_SECRET
Command
https://docs.docker.com/compose/reference/
up
Create and start containers
down
Stop and remove containers, networks, images, and volumes
start
Start services
stop
Stop services
exec
Execute a command in a running container
run
Run a one-off (one-time) command
$ docker-compose run web bash
--rm Remove container after run. Ignored in detached mode.