프로젝트 구조
1
2
3
app/main.py
Dockerfile
docker-compose.yml
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Dockerfile
# pull the official docker image
FROM python:3.9.4-slim
# set work directory
WORKDIR /app
# set env variables
# Prevents Python from writing pyc files to disc
ENV PYTHONDONTWRITEBYTECODE 1
# Prevents Python from buffering stdout and stderr
ENV PYTHONUNBUFFERED 1
# install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt
# copy project
COPY . .
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
# docker-compose.yml
version: '3.8'
services:
web:
build: .
command: uvicorn app.main:app --host 0.0.0.0
volumes:
- .:/app
ports:
- 8000:8000
Docker build & run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
docker-compose build
docker-compose up -d
docker-compose up -d --build
docker-compose -f <docker-compose.yml> up -d --build
docker-compose down -v
#When finished
docker-compose down
#Check console output
docker-compose logs
docker-compose logs app #Check only app service log
#Go inside the app container
docker-compose run app bash