Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Jenkins master and slave with Docker

I want to setup Jenkins master on server A and slave on server B with use of Docker.

Both servers are virtual machines dedicated for Jenkins.

Currently I have started Docker container on server A for master, based on the official Jenkins docker image. But what docker image should I use for Jenkins slave?

like image 214
Ismar Slomic Avatar asked Sep 24 '16 22:09

Ismar Slomic


People also ask

Can we integrate Jenkins with Docker?

Jenkins uses a REST API for communicating with Docker. The following configuration steps on the Docker host ensure that the Jenkins controller can connect properly. 1. Use a tool such as Nmap to check if the relevant ports are open.

How do Docker and Jenkins work together?

Jenkins builds a new docker image and pushes it to the Docker registry. Jenkins notifies Kubernetes of the new image available for deployment. Kubernetes pulls the new docker image from the docker registry. Kubernetes deploys and manages the docker instance/container.


2 Answers

That actually depends on the environment and tools you need in your build environment. For example, if you build a C project, you would need an image containing a C compiler and possibly make if you use Makefiles. If you build a Java project, you would need a JDK with a Java compiler and possibly Ant / Maven / Gradle if you use them as part of your build.

You can use the evarga/jenkins-slave as a good starting point for your build slave.

This image already contains JDK. If you simply need JDK and Maven on your build slave, you can build your Docker image with the following Dockerfile:

FROM evarga/jenkins-slave

run apt-get install maven

Using Docker images for build slaves is actually a good idea. Some of the reasons appear at Templating Jenkins Build Environments with Docker Containers:

Docker has established itself as a popular and convenient way to bootstrap isolated and reproducible environments, which enables Docker containers to be the most maintainable slave environments. Docker containers’ tooling and other configurations can be version controlled in an environment definition called a Dockerfile, and Dockerfiles allows multiple identical containers can be created quickly using this definition or for more customized off-shoots to be created by using that Dockerfile’s image as a base.

like image 152
Alon Avatar answered Oct 12 '22 08:10

Alon


I suggest you take trying to use dynamic|ephemeral docker nodes, instead of manually creating nodes and connecting to them via ssh. Take a look at https://engineering.riotgames.com/news/putting-jenkins-docker-container, it's very powerful and I think it's one of killer usecases for Docker.

like image 34
ufoolme Avatar answered Oct 12 '22 06:10

ufoolme