Should I add user: root when creating jenkins server with docker compose?

I have searched some tutorials for creating Jenkins server with docker-compose but I still not sure if I need to add user: root or not. And how can I improve this docker-compose file?

Here is my docker-compose file:

version: '3'
services:
  jenkins:
    container_name: jenkins-server
    image: jenkins/jenkins:2.375.3-lts-jdk11
    # user : root
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - /home/jenkins_home:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 8080:8080
      - 50000:50000
    restart: always
    privileged: true
    environment:
      - "JENKINS_JAVA_OPTS=-Xmx512g -Xms512g"

Thanks

Unless you have some pressing need for jenkins to be running as root, which is very dangerous, i don’t see why you’d want it to be root.

1 Like

Personally, I am not sure if there are any permission issues if not using the root user. Because the permission of my /home/jenkins_home folder is root:root. Perhaps I need to change to folder location?

Hi @longkang :wave:

To me, there is no need at all to be root for this container.
Change directory, or change the owner…
And then, you’ll maybe get in trouble because of UID. :thinking:
@dduportal educated me on this particular subject several times, and I have forgotten about that.
I am now using anonymous volumes so I don’t have this particular issue anymore. :person_shrugging:

Hi @poddingue

Thanks so much for your reply. I am now getting more clear about this issue.

Anonymous volumes sound great to me and I will give it a try.

And! Thanks for sharing the compose file!

1 Like