# Step 1: Use base image
FROM python:3.9-slim
# Step 2: Set working directory
WORKDIR /app
# Step 3: Copy local requirements file into container
COPY [Link] .
# Step 4: Install dependencies
RUN pip install --no-cache-dir -r [Link]
# Step 5: Copy all application files into container
COPY . .
# Step 6: Add an external file (example: [Link] or remote file)
ADD [Link] /app/[Link]
# Step 7: Expose a port (e.g., for Flask app)
EXPOSE 5000
# Step 8: Set entrypoint to python (always runs)
ENTRYPOINT ["python"]
# Step 9: Default command to run (can be overridden)
CMD ["[Link]"]
Explanation
FROM python:3.9-slim → Base image with Python 3.9.
WORKDIR /app → All commands will execute inside /app.
COPY [Link] . → Copies [Link] into the container.
RUN pip install --no-cache-dir -r [Link] → Installs Python dependencies.
COPY . . → Copies application code into /app.
ADD → Adds an external file (here we pulled a remote README and stored as
[Link]). Unlike COPY, ADD can also fetch URLs and extract tar files.
EXPOSE 5000 → Informs Docker that the app runs on port 5000.
When we write EXPOSE 5000 in a Dockerfile, it means:
Our application inside the container is listening on port 5000.
It’s just a way of documenting or telling Docker and other developers:
“Hey, this app uses port 5000 for communication.”
⚠️ But important point:
EXPOSE does not actually publish the port to the outside world.
To make it accessible, we need to:
Use -p flag when running:
docker run -p 5000:5000 myapp
(maps container port 5000 → host port 5000)
Or in AWS, open the port in Security Groups / Load Balancers / Ingress.
ENTRYPOINT ["python"] → Makes Python the default executable.
CMD ["[Link]"] → By default, it will run python [Link]. If we pass arguments, they
replace CMD.