Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantages of running Jenkins in a docker container

I've found quite a few blogs on how to run your Jenkins in Docker but none really explain the advantages of doing it.

These are the only reasons I found:reasons to use Docker.

1) I want most of the configuration for the server to be under version control.

2) I want the ability to run the build server locally on my machine when I’m experimenting with new features or configurations

3) I want to easily be able to set up a build server in a new environment (e.g. on a local server, or in a cloud environment such as AWS)

Luckily I have people who take care of my Jenkins server for me so these points don't matter as much. Are these the only reasons or are there better arguments I'm overlooking, like automated scaling and load balancing when many builds are triggered at once (I assume this would be possible with Docker)?

like image 663
qacwnfq q Avatar asked Jun 08 '17 15:06

qacwnfq q


People also ask

Can we run Jenkins in Docker?

Note that while recent versions of Windows gained native support for running Docker images, Jenkins only provides Linux based Docker images. Windows and macOS can run Linux Docker images through virtualization, so most of the commands shown here apply equally to all operating systems, but this post will focus on Linux.

What is an example of an advantage of creating a Docker volume inside a Jenkins container?

Docker instances are easier to manage if you are interested in running Jenkins on multiple platforms. You can easily create and destroy the Jenkins server and remove all the Jenkins data.


2 Answers

This answer for Docker, what is it and what is the purpose covered What is docker? and Why docker? Docker official site also provides an explanation.
The simple guide here is:

Faster delivery of your applications
Deploy and scale more easily
Get higher density and run more workloads
Faster deployment makes for easier management

For Jenkins usage, it's faster and easier to deploy/install in the docker way. Maybe you don't need the scale more easily feature right now. And since the docker is quite lightweight, so you can run more workloads.

However

The docker way would also bring some other problem. Generally speaking, it's the accessing privilege.
Like when you need to run Docker inside the Jenkins(in Docker), it would become complicated somehow. This blog would provide you with some knowledge of that situation.

So there is no silver bullet as always. There is no single development, in either technology or in management technique, that by itself promises even one order-of-magnitude improvement in productivity, in reliability, in simplicity.

The choice should be made based on the specific scenario.

like image 54
Shihe Zhang Avatar answered Oct 24 '22 10:10

Shihe Zhang


Jenkins as Code

You list mainly the advantages of having "Jenkins as Code". Which is a very powerfull setup indeed, but does not necessary requires Docker.

So why is Docker the best choice for a Jenkins as Code setup?

Docker

The main reason is that Jenkins pipelines work really well with Docker. Without Docker you need to install additional tools and add different agents to Jenkins. With Docker,

  • there is no need to install additional tools, you just use images of these tools. Jenkins will download them from internet for you (Docker Hub).
  • For each stage in the pipeline you can use a different image (i.e. tool). Essentially you get "micro Jenkins agents" which only exists temporary. Hence you do not need fixed agents anymore. This makes your Jenkins setup much more clean.

Getting started

A while ago I have written an small blog on how to get started with Jenkins and Docker, i.e. create a Jenkins image for development which you can launch and destroy in seconds.

like image 30
Dirc Avatar answered Oct 24 '22 12:10

Dirc