ν’€μŠ€νƒ μ›ΉπŸŒ 개발자 지망생 πŸ§‘πŸ½β€πŸ’»
βž• 인곡지λŠ₯ 관심 πŸ€–


Categories


Recent views

  • 1
  • 2
  • 3
  • 4
  • 5

docker-compose κ°œλ…

docker-compose

docker-composeλ₯Ό μ΄μš©ν•œλ‹€λ©΄ μ—¬λŸ¬ 도컀 μ»¨ν…Œμ΄λ„ˆμ˜ 연계와 섀정을 μ†μ‰½κ²Œ ν•  수 μžˆλ‹€.

docker-compose μ„€μΉ˜

λ¨Όμ € docker-composeλ₯Ό κΉ”κΈ° μœ„ν•΄ μ•žμ„  Dockerκ°€ μ„€μΉ˜λ˜μ–΄μ•Ό μžˆμ–΄μ•Ό ν•œλ‹€.

  • [Install Docker Compose CLI plugin Docker Documentation](https://docs.docker.com/compose/install/) μ°Έκ³ (μ΅œμ‹  λ²„μ „μœΌλ‘œ μ—…λ°μ΄νŠΈ λ˜λŠ” μ½”λ“œ)
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.14.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose

λ§Œμ•½, 무쑰건 μ΅œμ‹ μ˜ docker-composeλ₯Ό λ‹€μš΄λ°›κ³  μ‹Άλ‹€λ©΄

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

λ§Œμ•½ μœ„ μ½”λ“œλ‘œ μ•ˆλœλ‹€λ©΄ κ·Έ μœ„μ— 적어 놓은 링크λ₯Ό μ°Έμ‘°ν•΄ 보자.

chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose

μœ„ μ½”λ“œλ₯Ό 톡해 docker-compose의 κΆŒν•œμ„ λ°”κΏ”μ€€λ‹€.

version: '3'

services:

  nginx:
    container_name: nginx # μ»¨ν…Œμ΄λ„ˆλͺ…
    build: ./nginx # dockerfile 경둜
    image: server_dev/nginx # λΉŒλ“œ ν›„ 이미지λͺ…
    restart: always # 죽으면 μž¬μ‹œμž‘
    ports:
      - "80:80"
    volumes: # μ»¨ν…Œμ΄λ„ˆκ°€ μ‚¬μš©ν•  μ €μž₯ 곡간, 이λ₯Ό 톡해 μ»¨ν…Œμ΄λ„ˆκ°€ 없어져도 μ €μž₯ κ³΅κ°„μ˜ 값은 λ‚¨μŒ
      - ./backend:/srv/docker-server/backend
      - ./log:/srv/docker-server/log/nginx
    depends_on: # λ¨Όμ € μ‹œμž‘ν•΄μ•Ό ν•˜λŠ” μˆœμ„œμ˜ μ»¨ν…Œμ΄λ„ˆ
    - django

  django:
    container_name: django 
    build: ./backend
    image: server_dev/django
    restart: always 
    command: uwsgi --ini uwsgi.ini # Dockerfile의 CMD λͺ…령문을 λ¬΄μ‹œν•˜κ³  μ‹€ν–‰ν•  λͺ…λ Ήμ–΄λ₯Ό μ„€μ •ν•˜κΈ° μœ„ν•΄μ„œ μ‚¬μš©λ©λ‹ˆλ‹€.
    volumes: 
      - ./backend:/srv/docker-server/backend
      - ./log:/srv/docker-server/log/uwsgi 

μœ„μ™€ 같이 docker-compose.yml을 μ„€μ •ν•  μˆ˜μžˆλ‹€. μ˜ˆμ œλŠ” λ°±μ—”λ“œ μ„œλ²„μ™€ μ›Ήμ„œλ²„λ₯Ό μ—°κ²°ν•˜λŠ” μ˜ˆμ œμ΄λ‹€.

sudo docker-compose up -d --build

  • -d : λ°±κ·ΈλΌμš΄λ“œ μ‹€ν–‰

  • --build : μƒˆλ‘œ 이미지λ₯Ό λΉŒλ“œ

μœ„μ™€ 같은 μ»€λ§¨λ“œλ‘œ Docker μ»¨ν…Œμ΄λ„ˆλ“€μ„ ν•œκΊΌλ²ˆμ— μ‹€ν–‰ν•  수 있고, 였λ₯˜κ°€ μ—†λ‹€λ©΄ μ•„λž˜μ™€ 이 μ»¨ν…Œμ΄λ„ˆκ°€ μ‹€ν–‰λœλ‹€. (μ˜ˆμ œλŠ” κΊΌμ ΈμžˆλŠ” μƒνƒœ)

sudo docker-compose ps // 도컀 μ»¨ν…Œμ΄λ„ˆλ“€μ˜ λͺ©λ‘ 보기
NAME                COMMAND                  SERVICE             STATUS              PORTS
django              "uwsgi --ini uwsgi.i…"   django              exited (137)        
nginx               "/docker-entrypoint.…"   nginx               exited (0)

πŸ”΅ λ‘œκΉ… μ„€μ • μΆ”μ²œ

참고둜, ν•œκΊΌλ²ˆμ— μ»¨ν…Œμ΄λ„ˆλ₯Ό μ‹€ν–‰ν•˜λ©΄μ„œ μ„œλ²„μ˜ λ©”μ‹œμ§€κ°€ μ½˜μ†”μ— κ²Ήμ³μ„œ 보이며, 데λͺ¬ μƒνƒœλ‘œ 싀행쀑 일 λ•ŒλŠ” μ•„μ˜ˆ 보이지 μ•ŠμœΌλ―€λ‘œ, 디버깅을 μœ„ν•΄ μ‚¬μš©ν•˜λŠ” 기술 μŠ€νƒμ˜ λ‘œκΉ…μ„ μ œλŒ€λ‘œ μ„€μ •ν•˜λŠ” 것이 μ’‹λ‹€.

> django  | [uWSGI] getting INI configuration from uwsgi.ini
> nginx   | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
> nginx   | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
> nginx   | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
> 

일반적으둜 μœ„μ™€ 같이 ν‘œμ‹œλœλ‹€.