Skip to content

Commit ce2a2b0

Browse files
Update python.md
1 parent 4cb4eae commit ce2a2b0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

β€Žrecipes/containers/docker/python.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@ container:
4040
docker run --rm myapp
4141
```
4242

43+
Multi-stage build, to avoid dev tools in the final image.
44+
45+
46+
```dockerfile
47+
FROM python:3.9-slim-buster as builder
48+
49+
WORKDIR /app
50+
51+
COPY requirements.txt .
52+
RUN pip install --no-cache-dir -r requirements.txt
53+
54+
COPY . .
55+
56+
FROM python:3.9-slim-buster
57+
58+
WORKDIR /app
59+
60+
COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
61+
COPY --from=builder /app .
62+
63+
EXPOSE 8000
64+
65+
CMD ["python", "app.py"]
66+
```
67+
4368

4469
## CLI only
4570

0 commit comments

Comments
Β (0)