Container Jenkins cannot find Docker command

Asked

Viewed 137 times

-1

in short, I’m trying to run one container inside another. Where the first container to go up is based on a Jenkins image and the second on a gcc image (which is only for testing).

this is the step by step of what I did:

  1. I raised a Jenkins container based on the image jenkins\jenkins with the following command:

    • docker run -it -p 1234:8080 -v jenkins_home:/var/jenkins_home -u 0 jenkins/jenkins

    • jenkins_home is a volume created with the command docker volume create jenkins_home

  2. I installed the plugins Docker, Docker Slaves and Docker Pipeline.

  3. I created a job pipeline:

    pipeline {
        stages {        
            stage('Container') {
                agent {
                    docker {
                        image 'gcc'
                        args '-v ${nomedocurso}:/curso/'
                    }
                }
                steps {
                    sh 'ls -l'
                }
            }
        }
    }
    
    • In that step, Jnenkins was not finding Docker:

      + Docker Inspect -f . gcc /var/jenkins_home/Workspace/curso-c@2@tmp/Durable-ee333f1e/script.sh: 1: /var/jenkins_home/Workspace/curso-c@2@tmp/Durable-ee333f1e/script.sh: Docker: not found

  4. I tried to include the label parameter:

    pipeline {
        agent {
            label 'docker' 
        }
        stages {        
            stage('Container') {
                agent {
                    docker {
                        label 'docker'
                        image 'gcc'
                        args '-v ${nomedocurso}:/curso/'
                    }
                }
                steps {
                    sh 'ls -l'
                }
            }
        }
    }
    
    • But Jenkins kept complaining:

      Still Waiting to Schedule task
      pra Jenkins' doesn’t have label ːDocker'


  • Because Docker’s not being found by Jenkins?
  • How to set up and run a Docker pipeline in one of the stages?
  • This Jenkins image does not have the Docker engine installed. If you want to handle containers using an image with Jenkins and Docker the best solution is to provision one with everything you need.

  • @Antonioazambuja you know some to recommend?

  • Can you verify the answer? Don’t forget to accept it if you are satisfied with it.

1 answer

1

You shouldn’t start a container inside another container. Although not impossible, it simply should not be done and "hurts" the purpose of containers.

This article (in English) talks a little about this and presents an alternative. It seems to me that it is for a scenario similar to yours: https://itnext.io/docker-in-docker-521958d34efd

There is also a project that allows you to do this in a simpler way, but it depends on the images being available in the project: https://www.testcontainers.org/

  • This helps me a little. However, as I am in windows I can’t find Docker.Sock! What I can do?

  • @Gabrielhardoim has tried without -v /var/run/docker.sock:/var/run/docker.sock?

  • I haven’t even tested that volume yet

Browser other questions tagged

You are not signed in. Login or sign up in order to post.