Jenkins is an open source automation tool written in Java with plugins built for Continuous Integration purpose. It is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. It also allows you to continuously deliver your software by integrating with a large number of testing and deployment technologies.
Docker is a platform for running applications in an isolated environment called a "container" (or Docker container). Docker Compose is a tool for defining and running Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. It lets you take advantage of the benefits of Docker while abstracting the complexity of your stack.
Installing Jenkins directly in your OS can be tricky and expensive in terms of time and resources. You need to have Java installed in your local machine and at least 10 GB of drive space. On the other hand, using docker compose is really straightforward and offers a lot of advantages.
We're going through the steps to install Jenkins using Docker-Compose.
Docker Desktop for Mac and Docker Toolbox already include Compose along with other Docker apps, so Mac users do not need to install Compose separately. Docker install instructions for these are here:
You can verify the version of docker compose using:
> docker-compose --version
docker-compose version 1.25.4, build 8d51620a
Inside your working directory create the docker-compose.yml file:
Then copy the following configuration:
You need to ensure the directory
This volume will be used to persist all your data: configurations, plugins, pipelines, passwords, etc.
The remaining two volumes allow you to use docker inside the Jenkins server (Yes, you can create docker containers inside a docker container).
> docker-compose up -d
Jenkins is running in
View the generated administrator password to log in the first time.
❯ docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
Now, you're ready to install plugins and start creating pipelines. If you want to stop the Jenkins container you can do it with
docker-compose down. When you restart it all your configuration, users, plugins previously installed will persist there.
To upgrade to latest versions just modify the tag of the image in your docker-compose yml file, for example:
That's it! You can start using Jenkins to implement your CI/CD.