How to run Jenkins in a Docker container
There's no need to perform a full-scale Jenkins installation on your local computer if you want to run pipeline builds.
All you need is a local installation of Docker and you can quickly install Jenkins inside a container. It's an incredibly efficient way to run Jenkins pipelines, as the container only runs when the builds run. There's no need to have a server constantly running in the background.
How to run Jenkins in Docker
To run Jenkins in a Docker container, simply issue a docker run command with the following configuration parameters:
- Use the
jenkins/Jenkins:lts
image to run the latest long-term support release. - Map the internal
JENKINS_HOME
directory to a folder on your local filesystem. - Optionally expose port 50000 if you need Jenkins agents to communicate with each other.
- Map the internal port 8080 to an available port on your local machine.
- Run the command as a privileged root user.
The Docker run command for Jenkins
When the steps are all pulled together into a single docker run
command, here's how it looks:
docker run --privileged -u 0 -p 8080:8080 -p 50000:50000 -v C://cicd/jh:/var/jenkins_home jenkins/jenkins:lts
This command pulls the Jenkins image from DockerHub and makes Jenkins available on port 8080 of your local machine.
When the Docker command completes, simply log into Jenkins, complete any initial installation steps, and then create build jobs and Jenkins pipelines as you normally would. You'll have all the features of Jenkins at your disposal, with the added benefit of not having to maintain a local installation of the tool.
Cameron McKenzie has been a Java EE software engineer for 20 years. His current specialties include Agile development; DevOps; Spring; and container-based technologies such as Docker, Swarm and Kubernetes.