-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
44 lines (31 loc) · 1.46 KB
/
Dockerfile
File metadata and controls
44 lines (31 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# docker image
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
RUN echo "Starting Docker build..."
RUN echo "Build time:: $(date)"
# set the working directory (app folder here)
# container has it's own filesystem within that we put all the files that need for a particular api like here app is the working directory.
WORKDIR /app
# install dependencies
COPY ./requirements.txt /app
# --no-cache-dir --upgrade-> prevents pip from using its local cache \
# and forces pip to download the package fresh from PyPI.
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# copy the scripts to the app folder
# everything on the root folder specify by `.` (dot), copy to app folder of docker container
COPY . /app
# . (destination) → current WORKDIR and WORKDIR =/app
# so, `COPY . .` also same.
# start the server (we internally run on port 80 (default port) on docker container)
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
# How Docker builds images:
# Docker builds images layer by layer.
# Each instruction in the Dockerfile creates one immutable layer.
# Docker reuses layers if nothing has changed in the layer.
# Why requirements.txt is copied separately ?
# COPY ./requirements.txt /app
# RUN pip install --no-cache-dir --upgrade -r requirements.txt
# Dependency installation runs only when requirements.txt changes
# Application code changes don't trigger reinstalling dependencies
# Builds become much faster