How Do You Get Jenkins Working in a Docker Container?

One of the following problems apply:

Problem scenario #1
You have no idea how to start Jenkins in a Docker container.  What should you do?

OR

Problem scenario #2
You have run some Docker commands to try to start deploy Jenkins in a container.  You get output like this:

[4213] [10236] Disconnected
[9146] Connection from [::1]:41118
[9146] Extended attributes (16 bytes) exist <host=localhost>
[9146] Request upload-pack for '/repo'
[4213] [10255] Disconnected

How do you get Jenkins running in a Docker container?

Solution
1.  Install Docker.  If you need assistance with this, see this posting.

2.  Start the Docker service (e.g., run "sudo service docker start")

3.  Run these two commands:

docker run -d -v /var/jenkins_home:/var/jenkins_home:z -p 8080:8080 -p 50000:50000 --name myjenkins jenkins/jenkins:lts

sudo chown 1000:1000 /var/jenkins_home

4.  Run this:  docker ps -a

5.  Look at the output of the above command.  Find the container ID that was just created with step #3.  Then run this command (but substitute abcd1234 with the container ID you just identified):

docker start abcd1234

6.  Docker should now be accessible via the Docker host's external IP address on port 8080.  You can run this on the host to find the external IP address: curl icanhazip.com

In a web browser you should be able to go to x.x.x.x:8080 (where x.x.x.x is the external IP address of the server returned in from the curl command above) and get to the Jenkins instance in the Docker container.

You may want to see this posting for your initial set up because it explains how to enter a Docker container if you are new to Docker.

Leave a comment

Your email address will not be published. Required fields are marked *