Sunday, 31 March 2024

Docker Cloud Agent in Jenkins

1. What to use Docker Cloud Agent for?
Docker Cloud Agent is a agent of Jenkins to clone source, build, test for CI.

2. How to use Docker Cloud Agent?
- Setting up Docker cloud Agents

3. What does Docker Cloud Agent include? 

--------------------------
Detailed instructions

* Setting up Docker Cloud Agents (1)
- Prerequisite: Docker installed
- Prepare to connect docker in host
+ Install Plugin cloud provider/ select plugin: Docker/ Download now and restart after install.
/ There are many plugins for Cloud providers: Docker, Kubernetes, Amazon EC2, Azure VM Agents,...
+ Build and run socat container (2) to connect Jenkins with Docker (running jenkins as container, the container can't reach docker host port).

docker run -d --restart=always -p 127.0.0.1:2376:2375 --network jenkins -v /var/run/docker.sock:/var/run/docker.sock alpine/socat tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock
docker inspect <container_id> | grep IPAddress

- Connect docker in host: Dashboard/ Manage Jenkins/ Manage nodes and clouds/ Configure Clouds/ (Go to plugin manager to install Plugin cloud provider)/Add a new cloud/ Select Docker/ Docker cloud detail/ Docker Host URI: tcp://<IPAddress_Socat>:2375/Check Enable/ Test Connection.
- Create Docker Agent templates (can create multiples): Add Docker Template/ Labels: Docker-agent-alpine/ checked Enabled/ Name: Docker-agent-alpine/ Docker Image: jenkins/agent alpine-jdk11/ Instance Capacity: 2/ Remote File System Root: /home/jenkins/ Save
+ Labels: for jobs select which agent should run the build.
+ Instance Capacity: is how many actually spawn.
+ Remote File System Root: workspace of Jenkins is going to get created.
- Using Agents in job: Select job/ Configure/ checked Restrict where this project can be run?/ Label Expression: Docker-agent-alpine/ Save/ Build job again/

Reference
- (1) (Setting up Docker Cloud Agents 00:33:40 Setting up Docker Cloud Agents)
- (2) Build and run socat container

No comments:

Post a Comment

Golang Advanced Interview Q&A