Skip to content

Commit a5d3d8e

Browse files
committed
Avoid separate chown to use less space in layers
1 parent 4062beb commit a5d3d8e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Dockerfile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,23 @@ RUN apt-get update && apt-get install -y \
6565
&& apt-get clean \
6666
&& rm -rf /var/lib/apt/lists/*
6767

68-
# Copy the virtual environment from the builder stage
69-
COPY --from=builder /app/.venv /app/.venv
70-
COPY --from=builder /app/artifacts /app/artifacts
71-
COPY --from=builder /app /app
68+
# Create the application user and docker group before copying app files so we
69+
# can set ownership in a single COPY layer instead of a separate chown layer.
70+
RUN useradd --create-home --shell /bin/bash app && \
71+
(groupadd -g 999 docker || true) && \
72+
usermod -aG docker app
73+
74+
# Copy the application and virtual environment from the builder stage with
75+
# correct ownership. This avoids an extra chown -R layer over /app.
76+
COPY --from=builder --chown=app:app /app /app
7277

7378
# Add the virtual environment to PATH
7479
# This allows us to run "uvicorn" or "python" directly without "uv run"
7580
ENV PATH="/app/.venv/bin:$PATH"
7681

77-
# Setup permissions
82+
# Install the entrypoint script
7883
COPY scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
79-
RUN chmod +x /usr/local/bin/docker-entrypoint.sh && \
80-
useradd --create-home --shell /bin/bash app && \
81-
groupadd -g 999 docker || true && \
82-
usermod -aG docker app && \
83-
chown -R app:app /app
84+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
8485

8586
USER app
8687

0 commit comments

Comments
 (0)