patterndockerMinor
Running Jenkins in docker with custom uid / gid
Viewed 0 times
uidjenkinsdockerwithgidcustomrunning
Problem
I have the following
I'm build a Jenkins container as follows:
I then run the image as follows:
I go to
I then create a job with a single shell command:
I run the job and I expect the output of the job to be
The output however, is
which seems to indicate that my
Why is this? The Jenkins Dockerfile should accept uid/gid as guild args.
Dockerfile:FROM jenkins/jenkins:latestI'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-jenkinsI go to
localhost:8080 and finish installation (without any plugins selected).I then create a job with a single shell command:
idI 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.
Solution
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
The
So why is
It is possible to use them in a reasonable straight forward way.
But I need to create my own
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.
TL;DR: It's not possible to use
--build-arg for FROM imagesThe
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-jenkinsBut 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.
Code Snippets
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-jenkinsContext
StackExchange DevOps Q#10594, answer score: 1
Revisions (0)
No revisions yet.