Skip to content

Instantly share code, notes, and snippets.

@carlosjgp
Created April 30, 2019 11:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosjgp/f6cb1fdaa740dbd037ab49545bc04b68 to your computer and use it in GitHub Desktop.
Save carlosjgp/f6cb1fdaa740dbd037ab49545bc04b68 to your computer and use it in GitHub Desktop.
Docker file ownership issue
# Image where non-root user is created and set as default
docker build -t abc -f Dockerfile-1 .
# Image where more files are copied and user is changed to root and back to non-root
docker build -t abc-2 -f Dockerfile-2 .
FROM busybox
ARG PUID=1000
ARG PGID=1000
RUN addgroup -g ${PGID} abc && \
adduser -D -u ${PUID} -G abc abc
USER abc
FROM abc
COPY file /home/abc
RUN ls -al /home/abc
USER root
RUN chown -R abc:abc /home/abc && \
ls -al /home/abc
USER abc
RUN ls -al /home/abc
Sending build context to Docker daemon 862.2kB
Step 1/5 : FROM busybox
---> af2f74c517aa
Step 2/5 : ARG PUID=1000
---> Using cache
---> 5f2412626bd1
Step 3/5 : ARG PGID=1000
---> Using cache
---> aa65960c0407
Step 4/5 : RUN addgroup -g ${PGID} abc && adduser -D -u ${PUID} -G abc abc
---> Using cache
---> e9130b459629
Step 5/5 : USER abc
---> Using cache
---> 93358e6f9609
Successfully built 93358e6f9609
Successfully tagged abc:latest
Sending build context to Docker daemon 862.2kB
Step 1/7 : FROM abc
---> 93358e6f9609
Step 2/7 : COPY file /home/abc
---> 577dcaea3383
Step 3/7 : RUN ls -al /home/abc
---> Running in 811df0055fd6
total 8
drwxr-sr-x 1 abc abc 4096 Apr 30 11:27 .
drwxr-xr-x 1 nobody nogroup 4096 Apr 30 10:46 ..
-rw-rw-r-- 1 root root 0 Apr 30 10:51 file
Removing intermediate container 811df0055fd6
---> 3528d33abd8d
Step 4/7 : USER root
---> Running in 3c3ae77cb445
Removing intermediate container 3c3ae77cb445
---> b156e940e3e6
Step 5/7 : RUN chown -R abc:abc /home/abc && ls -al /home/abc
---> Running in a4c13880d019
total 16
drwxr-sr-x 1 abc abc 4096 Apr 30 11:27 .
drwxr-xr-x 1 nobody nogroup 4096 Apr 30 10:46 ..
-rw-rw-r-- 1 abc abc 0 Apr 30 10:51 file
Removing intermediate container a4c13880d019
---> 41bd4567efbd
Step 6/7 : USER abc
---> Running in 48bf1fe9c72d
Removing intermediate container 48bf1fe9c72d
---> cf618921a61c
Step 7/7 : RUN ls -al /home/abc
---> Running in 4f171b287f07
total 8
drwxr-sr-x 1 abc abc 4096 Apr 30 11:27 .
drwxr-xr-x 1 nobody nogroup 4096 Apr 30 10:46 ..
-rw-rw-r-- 1 abc abc 0 Apr 30 10:51 file
Removing intermediate container 4f171b287f07
---> 3b8d3769da55
Successfully built 3b8d3769da55
Successfully tagged abc-2:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment