Dockerfile.python
attributes
| source_path | assets/Dockerfile.python |
|---|---|
| source_sha256 | c3f4c4d3f0ee27f6dbe5022db721daf641a569d34ae017d0999b251f00d0a78b |
| source_url | https://github.com/docker/skills/blob/ce4693b88722334625780ca8e9d54201b2d96f6d/skills/docker-build-strategies/assets/Dockerfile.python |
| supporting_skill_id | 40167 |
| upstream_revision | ce4693b88722334625780ca8e9d54201b2d96f6d |
# syntax=docker/dockerfile:1
# --- Build stage ---
FROM python:3.13-slim AS build
WORKDIR /src
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Install dependencies (cached separately from source); bind-mount the
# manifest since pip install -r never rewrites it
RUN --mount=type=bind,source=requirements.txt,target=requirements.txt \
--mount=type=cache,target=/root/.cache/pip \
pip install --no-compile -r requirements.txt
# Copy application source
COPY . .
# --- Runtime stage ---
FROM python:3.13-slim AS runtime
WORKDIR /app
RUN addgroup --system --gid 1001 appgroup && \
adduser --system --uid 1001 --ingroup appgroup appuser
# Copy virtual environment and application from build stage
COPY --from=build --chown=appuser:appgroup /opt/venv /opt/venv
COPY --from=build --chown=appuser:appgroup /src /app
ENV PATH="/opt/venv/bin:$PATH"
USER appuser
EXPOSE 8000
LABEL org.opencontainers.image.source="<source-repository-url>"
ENTRYPOINT ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0"]
Children
No children yet.
Like how this is organised?
Build your own Memory tree on knowen.md: notes, decisions and tasks in one connected markdown graph, shared with your team and your AI agents.