✔️

Docker Compose

도커 컴포즈란?

도커 컴포즈 설치

Install the Compose standalone
On this page you can find instructions on how to install the Compose standalone on Linux or Windows Server, from the command line. Compose standalone Note that Compose standalone uses the -compose syntax instead of the current standard syntax compose. For example type docker-compose up when using Compose standalone, instead of docker compose up.
https://docs.docker.com/compose/install/other/
curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

ls -l /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

#버전확인
docker-compose version

yaml 명령어

도커 컴포즈로 동작시키는 웹서버

mkdir composetest
cd composetest

#app.js 파이썬 파일 작성
import time
import redis
from flask import Flask

app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)

def get_hit_count():
    retries = 5
    while True:
        try:
            return cache.incr('hits')
        except redis.exceptions.ConnectionError as exc:
            if retries == 0:
                raise exc
            retries -= 1
            time.sleep(0.5)

@app.route('/')
def hello():
    count = get_hit_count()
    return 'Hello World! I have been seen {} times.\n'.format(count)


#requirements.txt 생성
flask
redis


#dockerfile생성
FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD ["flask", "run"]

cat > docker-compose.yml
version: "3.9"
services:
  web:
    build: .
    ports:
      - "8000:5000"
  redis:
    image: "redis:alpine"

출처 : 유튜브 따배런 따배도 https://www.youtube.com/@ttabae-learn
# 실행(백그라운드 모드로)
docker-compose up -d

# 도커 컴포즈로 만든 프로세스 조회
docker-compose ps

# 스케일 아웃
docker-compose scale mysql=2

docker-compose ps

# rm명령어처럼, 완전히 종료
docker compose down