Docker COPY --chown ownership sometimes applies to

522 Views Asked by At

I have the following Dockerfile

FROM python:3.11

# Create non-root user to run with
ARG USERNAME=bean
ARG USER_UID=999
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
COPY --chown=$USERNAME:$USERNAME . .

When I run the image, the copied subdirectories are owned by user bean, as is the working directory, .. When I build in AWS CodePipeline with the same build command, the copied subdirectories are owned by bean, but the . directory is owned by root. I can't reproduce the issue when building locally, even if I change ownership of the host directory to root or build as root. How can I make sure . is always owned by bean?

0

There are 0 best solutions below