This repository was archived by the owner on Jun 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
This repository was archived by the owner on Jun 3, 2025. It is now read-only.
USER command should not require user or group IDs to exist #477
Copy link
Copy link
Closed
Labels
area/dockerfile-commandFor all bugs related to dockerfile file commandsFor all bugs related to dockerfile file commandsarea/uidcategorizeddiffers-from-dockergood first issueGood for newcomersGood for newcomersissue/USERissue/unknown-userkind/bugSomething isn't workingSomething isn't workingkind/enhancementNew feature or requestNew feature or requestpriority/p0Highest priority. Break user flow. We are actively looking at delivering it.Highest priority. Break user flow. We are actively looking at delivering it.works-with-docker
Description
It is common for a Dockerfile to contain a USER directive of the form USER 1000:1000. docker build does not require a user and group with those ids to exist, nor does it create them. However, Kaniko errors.
Interestingly, while creating a minimal dockerfile to demonstrate this I discovered that Kaniko errors in two different ways:
Working example using Docker:
$ cat usertest1
FROM alpine
USER 1000:1000
CMD ["whoami"]
$ docker build --file usertest1 -t usertest:1 .
Sending build context to Docker daemon 23.46MB
Step 1/3 : FROM alpine
---> 196d12cf6ab1
Step 2/3 : USER 1000:1000
---> Using cache
---> 4794c572f720
Step 3/3 : CMD ["whoami"]
---> Using cache
---> 6ab640ab2641
Successfully built 6ab640ab2641
Successfully tagged usertest:1
$ docker run --rm usertest:1
whoami: unknown uid 1000
Kaniko failure mode 1
$ cat usertest1
FROM alpine
USER 1000:1000
CMD ["whoami"]
$ docker run --rm -it -v $PWD:/workspace gcr.io/kaniko-project/executor:latest --dockerfile=usertest1 --no-push --context=dir:///workspace
INFO[0000] Downloading base image alpine
2018/12/04 13:25:52 No matching credentials were found, falling back on anonymous
INFO[0001] Taking snapshot of full filesystem...
INFO[0001] Skipping paths under /dev, as it is a whitelisted directory
INFO[0001] Skipping paths under /kaniko, as it is a whitelisted directory
INFO[0001] Skipping paths under /proc, as it is a whitelisted directory
INFO[0001] Skipping paths under /sys, as it is a whitelisted directory
INFO[0001] Skipping paths under /workspace, as it is a whitelisted directory
INFO[0001] USER 1000:1000
INFO[0001] cmd: USER
error building image: error building stage: open /etc/passwd: no such file or directory
Kaniko failure mode 2:
Note the addition of the RUN directive and the different error message from Kaniko
$ cat usertest2
FROM alpine
RUN test 0
USER 1000:1000
CMD ["whoami"]
$ docker run --rm -it -v $PWD:/workspace gcr.io/kaniko-project/executor:latest --dockerfile=usertest2 --no-push --context=dir:///workspace
INFO[0000] Downloading base image alpine
2018/12/04 13:32:00 No matching credentials were found, falling back on anonymous
INFO[0001] Unpacking rootfs as cmd RUN test 0 requires it.
INFO[0001] Taking snapshot of full filesystem...
INFO[0001] Skipping paths under /dev, as it is a whitelisted directory
INFO[0001] Skipping paths under /kaniko, as it is a whitelisted directory
INFO[0001] Skipping paths under /proc, as it is a whitelisted directory
INFO[0001] Skipping paths under /sys, as it is a whitelisted directory
INFO[0001] Skipping paths under /workspace, as it is a whitelisted directory
INFO[0001] RUN test 0
INFO[0001] cmd: /bin/sh
INFO[0001] args: [-c test 0]
INFO[0001] Taking snapshot of full filesystem...
INFO[0001] Skipping paths under /dev, as it is a whitelisted directory
INFO[0001] Skipping paths under /kaniko, as it is a whitelisted directory
INFO[0001] Skipping paths under /proc, as it is a whitelisted directory
INFO[0001] Skipping paths under /sys, as it is a whitelisted directory
INFO[0001] Skipping paths under /workspace, as it is a whitelisted directory
INFO[0001] No files were changed, appending empty layer to config. No layer added to image.
INFO[0001] USER 1000:1000
INFO[0001] cmd: USER
error building image: error building stage: user: unknown userid 1000
thezultimate, benkn, duanshiqiang, strubel, mamoit and 11 more
Metadata
Metadata
Assignees
Labels
area/dockerfile-commandFor all bugs related to dockerfile file commandsFor all bugs related to dockerfile file commandsarea/uidcategorizeddiffers-from-dockergood first issueGood for newcomersGood for newcomersissue/USERissue/unknown-userkind/bugSomething isn't workingSomething isn't workingkind/enhancementNew feature or requestNew feature or requestpriority/p0Highest priority. Break user flow. We are actively looking at delivering it.Highest priority. Break user flow. We are actively looking at delivering it.works-with-docker