여기선 nginx와 postgresql을 활용한 구조로 구성했습니다.
version: "3.8"
services:
nginx:
image: nginx:latest
container_name: nginx
ports:
- "80:80"
volumes:
- ./static:/code/static
- ./config/nginx/:/etc/nginx/conf.d
depends_on:
- web
nginx.conf file
upstream web {
ip_hash;
server web:8000; # container_name
}
server {
location / {
proxy_pass http://web/;
}
listen 80;
server_name localhost;
}
web:
build:
context: .
dockerfile: Dockerfile
container_name: web
command: gunicorn docker_pjt.wsgi:application --bind 0.0.0.0:8000
ports:
- "8000:8000"
volumes:
- .:/code
depends_on:
- db
db:
image: postgres:latest
container_name: db
expose:
- "5432"
volumes:
- ./db_data:/code/db_data
environment:
- POSTGRES_DB=django
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
docker-compose up --build (빌드 후 실행)
docker-compose build (only build)
docker-compose up (only 실행)