Running Jenkins in docker with custom uid / gid
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.