Using Docker in jenkins with jenkins Docker agent
Getting Jenkins CI to build Docker container with a jenkins Docker agent
The problem
Running Jenkins CI agents as containers is a nice thing. However it can be a hassle if you want to build a container inside the containerized docker agent. Using the standard Jenkins agent container will result in an error telling you that the Docker binary is not found.
The solution
The default Jenkins agent container doesn’t contain the Docker binaries. 😔
But the Jenkins JNLP agent Docker container does! 😀
Unfortunately the image is missing any description and finding any documentation is hard. You can neither view the Dockerfile nor is the source linked. But in the GitHub repository for the JNLP Agents is a subdirectory called docker
in which you can find this Dockerfile. This seems to be the source for the linked image. One can see that the Docker binary is getting installed on build time.
In order to use the agent go to your Jenkins server settings and click on Manage Nodes and Clouds
→ Configure Clouds
.
If you haven’t already set your Docker settings:
Name: docker
Docker Host URI: unix:///var/run/docker.sock

Then open the Docker Agent templates section.
Change the Docker Image to: jenkins/jnlp-agent-docker

After that open the container settings and set the following:
User: root
Volumes: /var/run/docker.sock:/var/run/docker.sock

Thats it. Happy dockerizing 🙂