learner
learner

Reputation: 316

Jenkins - Docker cloud agent VS Docker in Pipeline

I'm trying to understand why so many people have taken the route of setting up "Docker cloud agent" (tutorial1, tutorial2) inside Manage Jenkins -> Clouds, instead of just going with "Docker agent" inside pipeline, which is officially supported (official documentation).

In my view, if I go with "Docker cloud agent" way,

  1. I have to login to the server where Jenkins is hosted.
  2. I need to edit Docker's service file "/lib/systemd/system/docker.service" and expose REST API port manually.
  3. Do the setup in Manage Jenkins Cloud.
  4. Create a Docker image of your own.
  5. Add that Docker image under "Docker agent template"
  6. Then finally refer that template's name in the pipeline.

UPDATE:

  1. Found one more disadvantage. We should always use the base image from "jenkins/agent" OR its variants (jenkins/agent:alpine:jdk11) and then on top of it, we need to install all the required libraries OR Software.

Instead of all these extra steps, if I go with "Docker agent" support inside pipeline directly (official documentation),

  1. I don't even need to login to server where Jenkins is hosted.
  2. I can also do more customization using "Dockerfile" and committing it to the source code.

What is the exact reason for choosing OR when should I choose "Docker cloud agent"?

And where is the official documentation to expose Jenkins REST API port like this?

Thank you.

Upvotes: 1

Views: 464

Answers (1)

Iterokun
Iterokun

Reputation: 2550

I don't know if I can give a comprehensive answer to this question, but there is one aspect that comes to mind - jobs isolation. When you are using docker-plugin (that provides Docker cloud) Jenkins creates a new agent for each job run. When you are using docker symbol in agent at the stage level you are reusing pipeline level agents, and when you are doing it at the pipeline level your containers are running on the controller, which is not scalable.

Generally speaking, single use agents are more deterministic and secure, so you will end up using them, and docker-cloud is probably the easiest way to do it. Not the best way for sure, as @alexander-pletnev mentioned k8s is probably more flexible.

Upvotes: 1

Related Questions