Docker Compose 파일의 구조

version: '3.7'

services:
	todo-web:
		image: diamol/ch06-todo-list
		ports:
			- "8020:80"
		networks:
			- app-net
networks:
	app-net:
		external:
			name: nat

문법

실습

  • 터미널 창을 열어 docker network를 생성해보자
  • 그 다음에는 docker compose 파일이 있는 디렉토리로 이동해 docker-compose 명령으로 애플리케이션을 시작해라

docker network create nat
cd ./ch07/exercises/todo-list
docker-compose up

Pasted image 20230609092522.png

docker compose를 사용해 여러 컨테이너로 구성된 애플리케이션 실행하기

accesslog:
	image: diamol/ch04-access-log

iotd:
	image: dimaol/ch04-image-of-the-day
	ports:
		- "80"
image-gallery:
	image: diamol/ch04-image-gallery
	ports:
		"8010:80"
	depends_on:
		- accesslog
		- iotd

Pasted image 20230609092555.png

실습

  • 터미널 창을 열어 예제 소스 코드의 최상위 디렉토리로 이동하고,
  • 다음과 같이 이미지 갤러리 애플리케이션의 디렉토리로 이동해 애플리케이션을 실행

cd ./ch07/exercise/image-of-the-day

docker-compose up -d
실습

  • 조금 전과 같은 터미널 창에서 도커 컴포즈를 사용해 iotd 서비스의 컨테이너 수를 늘려 보자
  • 그리고 웹 페이지를 리프레시하며 iotd 컨테이너 로그를 살펴보라

docker-compose up -d --scale iotd=3

docker-compose logs --tail=1 iotd
실습

  • docker compose 를 사용해 애플리케이션을 중지한 다음 재시작 하기
  • 컨테이너 목록을 보고 애플리케이션 스케일링 상태를 확인

docker-compose down

docker-compose up -d

docker container ls

Pasted image 20230609100153.png

docker container 간 통신

실습

  • 컨테이너 수를 세배로 늘려 docker compose로 애플리케이션을 실행하라
  • 웹 컨테이너에 DNS 조회 명령을 실행해 보자

docker-compose -d scale --iotd=3

# 리눅스 컨테이너
docker container exec -it image-of-the-day_image-gallery_1 sh

# 윈도 컨테이너
docker container exec -it image-of-the-day_image-gallery_1 cmd

nslookup accesslog

exit
실습

  • docker 명령형으로 accesslog 컨테이너 삭제하기
  • docker compose 로 애플리케이션을 재 실행하기
  • 웹 컨테이너에서 다시 셸을 실행해 DNS 조회를 다시 실행해보기

docker container rm -f image-of-the-day_accesslog_1

docker-compose up -d --scale iotd=3

# 리눅스 컨테이너
docker container exec -it image-of-the-day_image-gallery_1 sh

# 윈도 컨테이너
docker container exec -it image-of-the-day_gallery_1 cmd

nslookup accesslog

nslookup iotd

exit

docker compose로 애플리케이션 설정 값 지정하기

services:

	todo-db:
		image:diamol/postgres:11.5
		ports:
			- "5433:5432"
		networks:
			- app-net

	todo-web:
		image: diamol/ch06-todo-list
		ports:
			- "8020:80"
		environment:
			- todo-db
		networks:
			- app-net
		secrets:
			- source: postgre-connection
			- target: /app/config/secret.json

Docker Compose도 만능은 아니다.


#Docker