docker-compose

BERT·2023년 5월 23일
0

Docker

목록 보기
6/7

docker-compose

Docker를 통해 multi-container application 정의 및 실행
-f : config file
default filename : docker-compose.yaml
builds, rebuilds, creates, starts

docker-compose : install

sudo apt -y install docker-compose

docker-compose : nginx

docker-compose를 작업할 디렉터리 생성
docker-compose.yml 파일 생성

mkdir ~/docker-compose
cd ~/docker-compose
vim docker-compose.yml

yml 파일 형식
https://yaml.org/

version: '3'
services:
        nginx_8080:
                image: nginx
                restart: always
                hostname: nginx1
                container_name: cmp_nginx1_1
                networks:
                        mynet:
                                ipv4_address: 172.20.0.10
                ports:
                        - 8080:80
networks:
        mynet:
                ipam:
                        driver: default
                        config:
                                - subnet: 172.20.0.0/24

실행

docker-compose up

docker compose 프로세스 확인

docker-compose ps

background에서 실행

docker-compose up -d

docker-compose : nginx : recreating

docker-compose.yml 파일 수정
ports 아래 추가

                volumes:
                        - /home/bert/nginx_doc_root:/usr/share/nginx/html

recreating

docker-compose up -d

recreating 전과 비교
CONTAINER ID 변경 NAMES 유지

binding 확인

Nginx 2개 설정

docker-compose2.yml 생성

실행 후 프로세스 확인

docker-compose -f docker-compose2.yml up -d
docker-compose -f docker-compose2.yml ps

stop

docker-compose -f docker-compose2.yml stop

rm

docker-compose -f docker-compose2.yml rm

docker : network

docker network ls

dockercompose_mynet 확인 가능

컨테이너 stop 후 네트워크가 멈췄다고 가정

docker-compose -f docker-compose2.yml stop
docker network rm dockercompose_mynet

recreating 시 문제 발생

docker-compose -f docker-compose2.yml up -d

--foce-recreate networkd 재생성

docker-compose -f docker-compose2.yml up --force-recreate -d

0개의 댓글