Skip to content

Commit

Permalink
feat: Docker Multi Build
Browse files Browse the repository at this point in the history
  • Loading branch information
zzsza committed Jan 29, 2024
1 parent 4603d21 commit efa26ad
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
21 changes: 21 additions & 0 deletions 03-docker/multi_stage_build/Dockerfile.multi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Stage 1: Build
FROM python:3.9 as build

WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --user --upgrade -r /app/requirements.txt

# Stage 2 : Runtime
FROM python:3.9-slim as runtime

WORKDIR /app

# 필요한 파일들을 빌드 스테이지에서 복사
COPY --from=build /root/.local /root/.local
COPY ./simple_webserver.py /app/simple_webserver.py

# 환경 변수 설정 : pip install 할 때 --user로 설치하면 /root/.local에 저장됨
ENV PATH=/root/.local:$PATH

# 애플리케이션 실행
CMD ["python", "simple_webserver.py"]
11 changes: 11 additions & 0 deletions 03-docker/multi_stage_build/Dockerfile.single
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Single Stage Build
FROM python:3.9

WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
COPY ./simple_webserver.py /app/simple_webserver.py

CMD ["python", "simple_webserver.py"]


1 change: 1 addition & 0 deletions 03-docker/multi_stage_build/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fastapi==0.105.0
15 changes: 15 additions & 0 deletions 03-docker/multi_stage_build/simple_webserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from fastapi import FastAPI
import uvicorn

# FastAPI 객체 생성
app = FastAPI()


# "/"로 접근하면 return을 보여줌
@app.get("/")
def read_root():
return {"Hello": "World"}


if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=8000)

0 comments on commit efa26ad

Please sign in to comment.