Docker hub has an official jenkins image and it is more than enough to deploy your test jenkins instance. I cannot comment on if you can use that image for production purposes.

In this post, I will explain how to deploy a jenkins image using docker.

Deploy Jenkins Using Docker

Follow the steps given below to set up the jenkins instance on your host using docker.

create a directory in your host to mount it as the jenkins workspace. Replace with the username of your host.

mkdir /home/<username>/data/jenkins -p

Deploy the jenkins container by mounting the host jenkins folder to the container using the following command.

docker run -u root -p 8080:8080 -v /your/ubuntu/data/jenkins:/var/jenkins_home jenkins

In the above command, I have used “-u root” to give jenkins user to have privileges on your host folder. ALternatively, you can find the jenkins process id and change the ownership of the host folder using that id.

Mounting the host folder as your jenkins_home is recomeneded for backups.

If you do not want to mount your host folder, you can use the following command to spin up a jenkins contianer

docker run -u root -p 8080:8080  jenkins