The following will setup jenkins and jenkins agents on host with docker. All the jenkins infrastructure will be inside docker including the build agents.
This will deploy Jenkins 2.530 with Docker plugin 1274.vc0203fdf2e74 as Docker container.
Should be installed:
- Git
- Docker
curl -sLS https://raw.githubusercontent.com/stavsap/Jenkins-On-Docker/main/jenkins-docker-deploy-linux.sh | bashcurl -sLS https://raw.githubusercontent.com/stavsap/Jenkins-On-Docker/main/jenkins-docker-update-linux.sh | bashcurl -sLS https://raw.githubusercontent.com/stavsap/Jenkins-On-Docker/main/jenkins-docker-remove-linux.sh | bashcurl -o deploy.bat https://raw.githubusercontent.com/stavsap/Jenkins-On-Docker/main/jenkins-docker-deploy-windows.bat && cmd /c deploy.bat && del deploy.batcurl -o clean.bat https://raw.githubusercontent.com/stavsap/Jenkins-On-Docker/main/jenkins-docker-remove-windows.bat && cmd /c clean.bat && del clean.batNote: Verified to be working on Windows 11 using Docker Desktop with the WSL2 backend.
After successful deployment, open a browser at http://localhost:8080.
Now you will be requested for the admin passphrase that you should be able to see im the final log print of the deployment.
Next, set up your first admin user.
There will be no Cloud plugins install after fresh deployment, go to cloud -> plugins and install Docker plugin.
After that, create new Cloud, select type Docker, and enter the following settings:
Docker Host URI:
tcp://alpine-socat:2375check the Enabled and test the connection.
Docker templates are used to associate the build process with specific agents. The Jenkins agent is responsible for executing the actual build.
In Docker Cloud, Jenkins agents are implemented as Docker containers. Examples of such agents can be found here.
To add an agent, navigate to your Docker Cloud settings and add a template under 'Docker Templates'.
Labels:
docker-alpine-jdk21Docker Image:
localhost:5000/myjenkinsagent-jdk21If one desires to build docker images inside docker jenkins agent, do not install docker runtime inside the agent.
Mount the host docker socket into the agent instead and use docker client.
The agent we built "localhost:5000/myjenkinsagent-jdk21" has a docker client already.
After setting up Docker Cloud with docker template using localhost:5000/myjenkinsagent-jdk21, add to Docker template settings under "Container Settings":
User:
rootNote: to avoid using root user in the container, define a user on the host that have access to docker run time and use the same user to run the agent.
Mounts
type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sockIf one desires to use jenkins docker agent that is without docker client, perform the following:
- set up a docker template with you desired agent, for example jenkins/agent-jdk11.
- In docker template settings change user to "root" (to be able to perform install of packages).
- In job pipeline add step to install docker client. for example for alpine image agent:
apk add --update --no-cache dockerFollow this guide to set up SSH connectivity to Git repositories to be able to work with them.



