Run Jenkins in the container
The more you work with automation, the more you will like the containers. They fit and scale correctly in CI/CD model and can be easily managed. The whole infrastructure for automation should be flexible, easy to maintain and extendable – containers fit perfectly into this model. So why not start from putting Jenkins in the container?
Benefits of running Jenkins in the container
Using the containers to run Jenkins includes all of the benefits of containers like scalability or security, but there are some additional ones if you provide proper configuration of two components:
- Dedicated networks for connections to other local resources
- Static volumes for specific folders
As another local resource, you can count you local Docker Repository where you store container images. Dedicated network, with no external exposure, will provide a secure channel to send
The static volumes are required to preserve some data when you remove or rebuild the container. The static volumes should cover at least folder /var/jenkins_home. This is the home directory where Jenkins stores all the dynamic components, but not its binaries. You will find there all projects, configuration, logs, and plugins
Such separation when you run Jenkins in containers is handy. To upgrade Jenkins, you need to download a new image from the repository and rebuild the
Running Jenkins in Docker
Jenkins developers maintain official repository on Docker Hub as
I do not like to start and maintain containers via docker command line no matter if the project consists of single or multiple
version: '3'
services:
jenkins:
image: 'jenkins/jenkins:latest'
restart: unless-stopped
ports:
- '50080:8080'
- '50443:8443'
- '50000:50000'
volumes:
- 'jenkins_home:/var/jenkins_home'
volumes:
jenkins_home:
driver: local
As described previously I use local volume for
You can find examples of docker-compose.yml configuration files to run Jenkins in the container on my repository. I wrote about it in my blog post https://blog.it-playground.eu/repository-with-docker-templates/