Run a Jenkins slave in docker AND access to docker cli from jobs
- Go to Jenkins > manage > node management
- Click Create a node
- Check Permanent Agent
- Set working directory to something like
/data/jenkins-slave
(if you specify something else, don't forget to also change the command below) - Save
- Download slave-agent.jnlp, open it to retrieve your secret
- Change the command below with the working directory you specified, your slave-agent URL and jenkins secret
- Run it
- Enjoy 👍
docker run --rm -v /data/jenkins-slave:/data/jenkins-slave -v /var/run/docker.sock:/var/run/docker.sock --rm fgribreau/jenkins-slave:latest java -jar /app/agent.jar -jnlpUrl "http://YOUR_OWN_JENKINS.com/computer/SLAVE_NAME/slave-agent.jnlp" -secret "JENKINS_SECRET"
Wonder why this is awesome? Check out the related blog post.
Check out How to start a Jenkins slave inside Docker on my blog, (spoiler: it only requires docker official java image).