diff --git a/03-docker/multi_stage_build/Dockerfile.multi b/03-docker/multi_stage_build/Dockerfile.multi new file mode 100644 index 0000000..c97af09 --- /dev/null +++ b/03-docker/multi_stage_build/Dockerfile.multi @@ -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"] \ No newline at end of file diff --git a/03-docker/multi_stage_build/Dockerfile.single b/03-docker/multi_stage_build/Dockerfile.single new file mode 100644 index 0000000..c42c81b --- /dev/null +++ b/03-docker/multi_stage_build/Dockerfile.single @@ -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"] + + diff --git a/03-docker/multi_stage_build/requirements.txt b/03-docker/multi_stage_build/requirements.txt new file mode 100644 index 0000000..c9c2c7d --- /dev/null +++ b/03-docker/multi_stage_build/requirements.txt @@ -0,0 +1 @@ +fastapi==0.105.0 \ No newline at end of file diff --git a/03-docker/multi_stage_build/simple_webserver.py b/03-docker/multi_stage_build/simple_webserver.py new file mode 100644 index 0000000..51ff9b4 --- /dev/null +++ b/03-docker/multi_stage_build/simple_webserver.py @@ -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)