I have the following Dockerfile:

FROM jenkins/jenkins:latest

I'm build a Jenkins container as follows:

docker build -t my-jenkins --build-arg uid=1003 --build-arg gid=1003 .

I then run the image as follows:

docker run -it -p 8080:8080 my-jenkins

I go to localhost:8080 and finish installation (without any plugins selected).

I then create a job with a single shell command:


I run the job and I expect the output of the job to be

+ id
uid=1003(jenkins) gid=1003(jenkins) groups=1003(jenkins)

The output however, is

+ id
uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins)

which seems to indicate that my --build-args for uid and gid are completely ignored.

Why is this? The Jenkins Dockerfile should accept uid/gid as guild args.

1 Answer 1


As usual I think I came up with the answers shortly after spelling out the problem carefully here. I would be great if someone could confirm that my understanding is correct.

TL;DR: It's not possible to use --build-arg for FROM images

The FROM command basically tells docker what binary image to start from. The FROM image is not built recursively. This obviously means that --build-arg won't be taken into account in the FROM image.

So why is uid and gid even ARGs in the first place if I can't use them?

It is possible to use them in a reasonable straight forward way. docker build accepts git repo URLs when building, so you can indeed kick off a Jenkins docker with custom uid and gid quite easily as follows:

docker build -t my-jenkins --build-arg uid=1003 --build-arg gid=1003 https://github.com/jenkinsci/docker.git
docker run -it -p 8080:8080 --rm my-jenkins

But I need to create my own Dockerfile :-(

If you really need to custobmize the Jenkins image and need a custom uid / gid, the best way forward is to change the uid / gid of the Jenkins user in your Dockerfile. The uid = 1000 and gid = 1000 is already hardwired when your part of the Dockerfile kicks in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.