An Interest In:
Web News this Week
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
- March 14, 2024
- March 13, 2024
July 19, 2021 11:14 am GMT
Original Link: https://dev.to/dhingrachief/run-docker-commands-inside-jenkins-docker-k6d
Run Docker commands inside Jenkins Docker container
Introduction
If you want to initiate docker containers from within you jenkin containers,this is what you have to do:
- In the Jenkins Dockerfile, add commands docker, docker-compose installed.
- bind mount the docker socket.
And thats it! This is how the Dockerfile looks like:
Jenkins Dockerfile
FROM jenkins/jenkins# Docker installUSER rootRUN apt-get update && apt-get install -y \ apt-transport-https \ ca-certificates \ curl \ gnupg2 \ software-properties-common \RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -RUN apt-key fingerprint 0EBFCD88RUN add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/debian \ $(lsb_release -cs) \ stable"RUN curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose \&& chmod +x /usr/local/bin/docker-composeRUN apt-get update && apt-get install -y docker-ce-cliUSER jenkins
Now to build the image:
docker build -t jenkins-docker .
To run the docker-image, including the volume mounts:
docker run -d --group-add $(stat -c '%g' /var/run/docker.sock) \-v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 -p 50000:50000 \-v `pwd`/jenkins:/var/jenkins_home --log-opt max-size=50k --log-opt max-file=5 --name jenkins -P jenkins-docker
Here you can see docker.sock file has been mounted.Also, jenkins_home folder has been mounted so that you can persist the information regarding your pipeline/configuration/users etc.
Dont forget to take backup of jenkins_home directory!
I have uploaded a makefile and a similar Dockerfile on github.
And thats it!
Original Link: https://dev.to/dhingrachief/run-docker-commands-inside-jenkins-docker-k6d
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To