In this tutorial I will cover how to setup an Jenkins environment using docker. It will focus on a scenario where Nginx serves Jenkins app. This using the latest updates to docker network. We will make use of the autocreated bridge network that generates hostnames inside docker. This will let us serve internal host and port so we can upstream in nginx and we only need to expose nginx’s external port. Having nginx in place also let us adapt our scenarios if we need to use SSL certificates.
Highlights
- Host Jenkins on either on-prem or cloud.
- Manage build nodes using snapshots.
- Exponentially grow your build nodes.
Lets get started
There are many ways you use docker, I chose to docker machine and docker-compose to do it in this guide. Creating a docker-machine
then
now you are ready to use docker-compose.
Clone my repo
this contains all the different configurations files needed to get started.
Most important files
- docker-compose.yml
- conf/jenkins-master.env
I chose to use Jenkins image from Blacklabelops as it’s preloaded with Java and configured to use environment file.
You edit the default setup of Jenkins by making changes to conf/jenkins-master.env.
Update these to your default configuration.
- JENKINS_ADMIN_USER
- JENKINS_ADMIN_PASSWORD
- JENKINS_PLUGINS
JENKINS_MASTER_EXECUTORS is set to 0 as you will use build nodes to execute builds.
Go gadget go
With docker network and using version 2 with docker-compose it automatically creates a bridge network and generates hostnames internally in docker. Then you only need to expose the port for nginx and the upstream uses container names. If you need to make updates don’t forget to check nginx/jenkins.conf so it matches.
Now you are ready to spin up the containers using
and use your favorite browser to manage your jenkins. If you don’t know the docker machine IP use
. Hoped this guide helped you or just inspired you to make something of your own.
Cheers Erik