Docker - WORKDIR Creates Directories
Which user do you think owns the src/
directory in this Dockerfile example?:
FROM alpine:3.13.2
RUN adduser -D wendy
USER wendy
WORKDIR src/
COPY --chown=wendy . src/
The answer?: root
This happens because WORKDIR
will create directories that don’t exist with the root
user.
What if you wanted wendy
to be the owner of that src/
directory?
You would need to COPY
the src/
directory into place before setting it as the WORKDIR
. For example:
FROM alpine:3.13.2
RUN adduser -D wendy
USER wendy
COPY --chown=wendy . src/
WORKDIR src/
More info: Closed GitHub Issue & Docker Code