There are a few Dockerfile in the Git repository for Jenkins Docker Images.
I found this one, which I think is a suitable example to look at:
In this file, the user is specified to have name jenkins and uid 1000.
Initially, I tried to create the following docker-compose.yaml file to run an instance of Jenkins.
# docker-compose.yaml
services:
jenkins:
image: jenkins/jenkins:lts
container_name: jenkins_lts
ports:
- 8090:8080
- 50000:50000
volumes:
- /home/user/jenkins_compose/jenkins_configuration:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
networks:
jenkins_network:
name: jenkins-network-1
driver: bridge
When I tried to start the container using docker compose up -d, I got errors relating to the Jenkins process inside the container being unable to obtain Read/Write access to /var/jenkins_home.
This volume is mounted using the path /home/user/jenkins_compose/jenkins_configuration on the host.
The user and group names are irrelevant, however the user id (UID) and group id (GID) are important.
This directory currently has UID and GID set to 1002:1002. That is the username and group for my WSL user.
What I don't understand is why the Dockerfile used to build this Jenkins Docker Image (assuming I am looking at the right file) specifies the user 1000.
On this system, the user id 1000 belongs to a user called ubuntu.
$ id -nu 1000
ubuntu
That seems to be the default username for a different version of WSL in other words, it was for a WSL Ubuntu 22.04, not the current one I am using which is 24.04.
In short: My question is this. Why specify a user id of 1000 when the Docker Image has no idea which user this will be when it runs, or even if this user id will exist. This is only known when the Docker Container runs.