<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abdelhafid El Bekkaoui</title>
    <description>The latest articles on DEV Community by Abdelhafid El Bekkaoui (@hafeed06).</description>
    <link>https://dev.to/hafeed06</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F955961%2F6d05df2d-efb0-42ff-824c-a2b83641ad64.png</url>
      <title>DEV Community: Abdelhafid El Bekkaoui</title>
      <link>https://dev.to/hafeed06</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hafeed06"/>
    <language>en</language>
    <item>
      <title>How to run docker from a Jenkins docker container that is already running without docker</title>
      <dc:creator>Abdelhafid El Bekkaoui</dc:creator>
      <pubDate>Wed, 26 Oct 2022 11:52:16 +0000</pubDate>
      <link>https://dev.to/hafeed06/how-to-run-docker-from-a-jenkins-docker-container-that-is-already-running-without-docker-4bmk</link>
      <guid>https://dev.to/hafeed06/how-to-run-docker-from-a-jenkins-docker-container-that-is-already-running-without-docker-4bmk</guid>
      <description>&lt;p&gt;Let's imagine the following scenario:&lt;/p&gt;

&lt;p&gt;You needed to implement some CI/CD for your project and since you have some knowledge about docker and its advantages you thought "You know what, I'm going to run Jenkins as a docker container"! And you did and were able to create a pipeline with build steps and everything was going wonderfully. &lt;/p&gt;

&lt;p&gt;Then you realised that maybe you want to build a docker image from within Jenkins, so you added a shell script to do so. But Oh-oh! Docker is not recognized and your build fails. &lt;/p&gt;

&lt;h1&gt;
  
  
  First Scenario : You have a Jenkins Docker container that can't run docker and you want to add docker to it.
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Step 1 : Install Docker
&lt;/h2&gt;

&lt;p&gt;In this scenario we will solve two issues. The first one is how to run docker inside the Jenkins container (Docker out of Docker). And the second one how to do so without losing your existing Jenkins configuration and pipelines. &lt;/p&gt;

&lt;p&gt;Let's assume you are using RHEL or Centos, first you need to install docker, if you are using a different Linux distrubtion &lt;a href="https://docs.docker.com/engine/install/centos/"&gt;check the documentation from docker &lt;/a&gt;on what commands to run to install it, it is pretty easy to read and straightforward : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FhZdMQkb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z8ibeq414ur5wfndnph8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FhZdMQkb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z8ibeq414ur5wfndnph8.png" alt="Image description" width="302" height="666"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo -i
whoami # Should show "root"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Run yum update
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum -y update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install docker
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum install -y yum-utils
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Notice that this repo is a centos repo while we are using Rhel, the reason is because docker is not supported for some versions of RHEL but centos's docker works fine on all version of Rhel&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum-config-manager \ 
    --add-repo \ 
    https://download.docker.com/linux/centos/docker-ce.repo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check if docker is installed :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2 : Run Jenkins container :
&lt;/h2&gt;

&lt;p&gt;To pull the jenkins image and run it as a docker container use the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run --name jenkins -p 8080:8080 -p 50000:50000 -d --restart=on-failure -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts-jdk11
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation : &lt;br&gt;
--name jenkins : We are giving a name to this container so we can distinguish it easily. You can name it jenkins or whatever you want. &lt;br&gt;
-p 8080:8080 -p 50000:50000 : We are mapping and exposing the ports here. Jenkins runs on port 8080 by default but we can map it to whatever port we want. So for example if you use -p 80:8080 you will be able to access Jenkins through port 80. &lt;br&gt;
-d : To run the container in detached mode (Or in the background) &lt;br&gt;
-v jenkins_home:/var/jenkins_home : Adding the jenkins_home volume. &lt;br&gt;
jenkins/jenkins:lts-jdk11: The Jenkins image we want to run from dockerhub repository. Repository owner: jenkins. Repository name: Jenkins. Version or tag is : lts-jdk11.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker logs jenkins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g5WAvUXG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wlkbb3ip2zpranc7tqro.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g5WAvUXG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wlkbb3ip2zpranc7tqro.png" alt="Image description" width="880" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Copy the password and head to : &lt;a href="http://yourdomain.com:8080"&gt;http://yourdomain.com:8080&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rcPukv17--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7wl83jwtjis9obm5aefl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rcPukv17--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7wl83jwtjis9obm5aefl.png" alt="Image description" width="880" height="604"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pkkI9u_g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tttdxkrqnmay8c579lo6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pkkI9u_g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tttdxkrqnmay8c579lo6.png" alt="Image description" width="880" height="613"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create credentials:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mfBU3pa3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/66pu5qz34zoxllin6w3p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mfBU3pa3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/66pu5qz34zoxllin6w3p.png" alt="Image description" width="880" height="615"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a simple Jenkins job
&lt;/h3&gt;

&lt;p&gt;Now Jenkins is Setup correctly. Click on add new Item to add our first Jenkins job to test if docker works. It is supposed to fail. For the sake of simplicity we will start a FreeStyle project : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DrBUXGG_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kcjscaro8jdq0lj0twmo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DrBUXGG_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kcjscaro8jdq0lj0twmo.png" alt="Image description" width="325" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N6znhV4l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jgz4bks4wmm43l4s7dr8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N6znhV4l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jgz4bks4wmm43l4s7dr8.png" alt="Image description" width="880" height="546"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u5cd31tg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nsyff7wwjwi4yqkali6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u5cd31tg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nsyff7wwjwi4yqkali6.png" alt="Image description" width="475" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Put the following in the shell command which will allow us to verify if docker exists or not inside our Jenkins :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker --version
docker ps -a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lsEQZhFP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwn6jk3k6muy6no1q1b5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lsEQZhFP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwn6jk3k6muy6no1q1b5.png" alt="Image description" width="880" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Run the build/job
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EiCxlKHf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6et8dfo6roslb1aij1q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EiCxlKHf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6et8dfo6roslb1aij1q.png" alt="Image description" width="880" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The build fails as expected &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ktGzIrL3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z13je7c9kdcypoqri3ax.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ktGzIrL3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z13je7c9kdcypoqri3ax.png" alt="Image description" width="880" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's see the logs of the build to verify that it was caused by missing docker : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sj5bN0Mm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r14h1i32xxt9upkbo4n2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sj5bN0Mm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r14h1i32xxt9upkbo4n2.png" alt="Image description" width="422" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kywhLXOP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wq3ip11cbi3bt391c8vj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kywhLXOP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wq3ip11cbi3bt391c8vj.png" alt="Image description" width="880" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 : Create a new Jenkins container from the existing container
&lt;/h2&gt;

&lt;p&gt;This step is not necessary, but I will put it here in case you already customized your current Jenkins container and want to keep  the customizations. &lt;/p&gt;

&lt;p&gt;What we will actually do is create an image from the existing container and run a container from the image we created. &lt;/p&gt;

&lt;p&gt;Basically we want to : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get the image of the current Jenkins container we are running &lt;/li&gt;
&lt;li&gt;Create a new image out of it (a copy) &lt;/li&gt;
&lt;li&gt;Create a New Jenkins container from this new image.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker commit jenkins my-jenkins-image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation of the command : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;jenkins : this is the name of our jenkins container. You can see its name by running "docker ps" or "docker ps -a" if it's not running. &lt;/li&gt;
&lt;li&gt;my-jenkins-image: The name of the output image. The image that we want to create from the existing container. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Result :
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CbVd3J0i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhvd0kjn8wl6mare0a66.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CbVd3J0i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhvd0kjn8wl6mare0a66.png" alt="Image description" width="756" height="70"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations. Now you have a "copy" of the old Jenkins image that you can use to create a new Jenkins container that keeps the customization. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 : How to keep the old configuration and files of the old Jenkins.
&lt;/h2&gt;

&lt;p&gt;Before we create a new Jenkins container that will be able to run docker commands inside it we want it to have the configuration and the files of the old Jenkins container. If we don't do this we will have to reinstate Jenkins, enter the master password again, set credentials, define pipelines ... We don't want to do that even in a small project, but if it's an entreprise grade project well, we definitely don't want to do that. &lt;/p&gt;

&lt;p&gt;In order to do that we will use volumes. What are docker volumes? Well the simplest explanation is that they allow you to connect and share the content of two directories. It's actually a bit more complex than that but this concept is sufficient for you to understand what they are and what are their usages. &lt;/p&gt;

&lt;p&gt;As an example let's say you and your friend have 2 computers. Your compuer is named A, and their computer is named B. You both have a folder called MyFolder which is empty. &lt;/p&gt;

&lt;p&gt;Now you want to connect the MyFolder on computer A to MyFolder on computer B. In a way that whatever files are in MyFolder in computer A will be in MyFolder in computer B. &lt;/p&gt;

&lt;p&gt;Computer A&lt;br&gt;
  My Folder&lt;br&gt;
      - hello.txt&lt;/p&gt;

&lt;p&gt;Computer B&lt;br&gt;
  My Folder&lt;br&gt;
      - hello.txt&lt;/p&gt;

&lt;p&gt;Now if you create a new file in My Folder on Computer B called goodbye.txt, it will "magically" appear on computer A as well ! &lt;/p&gt;

&lt;p&gt;Computer A&lt;br&gt;
  My Folder&lt;br&gt;
      - hello.txt&lt;br&gt;
      - goodbye.txt&lt;br&gt;
Computer B&lt;br&gt;
  My Folder&lt;br&gt;
      - hello.txt&lt;br&gt;
      - goodbye.txt&lt;/p&gt;

&lt;p&gt;So the two folders are basically interlinked. &lt;br&gt;
In our case what we want to do is mount the configuration files that are in the old (current) Jenkins container and mount them to the new Jenkins container we want to create. &lt;/p&gt;
&lt;h3&gt;
  
  
  Copy the Jenkins configuration files from the old Jenkins container to a local folder on your host machine:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker cp jenkins:/var/jenkins_home /usr/jenkins-data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Explanation: &lt;br&gt;
jenkins:/var/jenkins_home : From container named "jenkins", copy the directory "/var/jenkins_home"&lt;/p&gt;

&lt;p&gt;/usr/jenkins-data: Where we want to copy this directory into&lt;/p&gt;

&lt;p&gt;Check if the data was copied :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls /var/jenkins_home # Should not be empty
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create the new Jenkins that can run docker
&lt;/h2&gt;

&lt;p&gt;Congratulations. You created an image from the old jenkins container and you copied the Jenkins data, which you will use to create a new Jenkins container that is exactly the same as the old one with the added benefit of it being able to run docker. &lt;/p&gt;

&lt;h2&gt;
  
  
  Stop the current Jenkins container
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker stop jenkins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create new jenkins container that can run docker
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -u 0 --name jenkins-docker -p 8080:8080 -p 50000:50000 -d --restart=on-failure -v /var/run/docker.sock:/var/run/docker.sock -v /usr/jenkins-data:/var/jenkins_home -v $(which docker):/usr/bin/docker my-jenkins-image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Check new container logs. It shouldn't show any password :
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker logs jenkins-docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Go to your &lt;a href="http://yourdomain.com:8080"&gt;http://yourdomain.com:8080&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zn-SEKWY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qdunalel7v0zhb1kke1u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zn-SEKWY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qdunalel7v0zhb1kke1u.png" alt="Image description" width="731" height="650"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that we are asked to log in and not to set up Jenkins even though we are running a new Jenkins container and not the old ones. This means that the configuration from the old Jenkins container is copied successfully. &lt;/p&gt;

&lt;p&gt;We also have the old job that we created. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cZMyACdK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nx89v883k48d4i1ju5hw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cZMyACdK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nx89v883k48d4i1ju5hw.png" alt="Image description" width="880" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Now build the job
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MRX2sqhH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j78dh9b6i4tg8ib0e3lq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MRX2sqhH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j78dh9b6i4tg8ib0e3lq.png" alt="Image description" width="880" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You see that the build is successful now &lt;br&gt;
See the logs : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0Xz6yd-N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y356zrpt1uw44bfei1ms.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0Xz6yd-N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y356zrpt1uw44bfei1ms.png" alt="Image description" width="880" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Important: Notice how when we run docker ps -a&lt;br&gt;
 we are getting a list of the containers of the docker that is installed on the Host machine! This is very important. Jenkins is now able to run not an installation of docker inside the jenkins container, but the installation of docker on the host itself. &lt;/p&gt;

&lt;p&gt;Basically running "docker ps -a" from a Jenkins shell script is the exact same as running it from your server's SSH with a root account. &lt;/p&gt;

&lt;p&gt;I hope this tutorial was helpful, it's my first time writing tutorials so there are some things to improve. Do not hesitate to leave any feedback. &lt;/p&gt;

</description>
      <category>jenkins</category>
      <category>docker</category>
      <category>containerapps</category>
    </item>
  </channel>
</rss>
