Docker-in-Docker OR Docker-outside-of-Docker ? Think Twice.

Image for post
Image for post
Image for post
Image for post
# image name
FROM centos:7
# some basic softwares
RUN yum install sudo -y
RUN yum install net-tools -y
RUN yum install wget -y
# setup jenkins repository
RUN wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
RUN rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key# installing jenkins + java is required
RUN yum install jenkins -y
RUN yum install java-11-openjdk.x86_64 -y
# append in the sudoers file so that jenkins can get sudo powers
RUN echo "jenkins ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# some softwares to run docker from inside
RUN yum install ca-certificates -y
RUN yum install curl -y
RUN yum install gnupg2 -y
RUN yum install dnf -y
# setup repository for docker
RUN dnf install 'dnf-command(config-manager)' -y
RUN dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo -y
# install docker
RUN yum install docker-ce -y
RUN sudo usermod -a -G docker jenkins
# this is the most important command
CMD chmod 777 /var/run/docker.sock && java -jar /usr/lib/jenkins/jenkins.war
Image for post
Image for post
# docker build tag <name>:<version> <path of Dockerfile>
docker build -t docker_siblings:v1 /tryproj/Dockerfile
Image for post
Image for post
docker run -it -p 8080:8080 -p 50000:50000 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /jenkins_home:/var/jenkins_home \
--name jenkins_docker docker_siblings:v1
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Manage Jenkins -> Configure Jenkins -> Cloud
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
This output shows the container is created
docker exec -it jenkins_docker bash
Image for post
Image for post

Worked in collaboration with Ashish Kumar.

Written by

Automation Tech Enthusiast || Terraform Researcher || DevOps || MLOps ||

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store