0

I am currently facing a situation whereby I can't pull a docker image during my Jenkins pipeline. Jenkins is running in a container as advised in the Jenkins Documentation

Whenever I run my pipeline, I come across the following error:

Started by user piii
Replayed #32
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/lms-portal
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
using credential 9d587d39-cf26-4eba-b08e-d9732a70a5b9
 > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/lms-portal/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/Piii-thagorus/lms_portal.git # timeout=10
Fetching upstream changes from https://github.com/Piii-thagorus/lms_portal.git
 > git --version # timeout=10
 > git --version # 'git version 2.30.2'
using GIT_SSH to set credentials jenksins_ssh
[INFO] SELinux is present on the host and we could not confirm that it does not apply actively: will try to relabel temporary files now; this may complain if context labeling not applicable after all
 > /usr/bin/chcon --type=ssh_home_t /var/jenkins_home/workspace/lms-portal@tmp/jenkins-gitclient-ssh9208860798294607535.key
Verifying host key using known hosts file
You're using 'Known hosts file' strategy to verify ssh host keys, but your known_hosts file does not exist, please go to 'Manage Jenkins' -> 'Configure Global Security' -> 'Git Host Key Verification Configuration' and configure host key verification.
 > git fetch --tags --force --progress -- https://github.com/Piii-thagorus/lms_portal.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/testing^{commit} # timeout=10
Checking out Revision 3e0e59d57c873b5869628455c28fc82d66f1570f (refs/remotes/origin/testing)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 3e0e59d57c873b5869628455c28fc82d66f1570f # timeout=10
Commit message: "Removed docker as agent"
 > git rev-list --no-walk 3e0e59d57c873b5869628455c28fc82d66f1570f # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . node:latest

error during connect: Get "https://docker:2376/v1.24/containers/node:latest/json": dial tcp: lookup docker: no such host
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker pull node:latest
error during connect: Post "https://docker:2376/v1.24/images/create?fromImage=node&tag=latest": dial tcp: lookup docker: no such host
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

Below is my pipeline, There

pipeline {

    agent {
        docker { image 'node:latest' }
    }

    stages {

        stage('Prepare'){
        
            steps{
                    sh 'echo "starting"'
            }
        }   
    }   
}

What can be the cause of this? Any solution is appreciated.

Thank you

mogale
  • 31
  • 8

2 Answers2

0

From what I understood you are running Jenkins as a container, and you want to run a build in which you require to pull a docker container.

If I am correct, let me make it clear.

You are running Jenkins as a docker container which means you do not have a local installation of Jenkins where you are running docker. Nor does Jenkins container run docker so you are trying to pull a docker container from where you do not have docker.

There is a work around for the same. You can install docker plugin and configure it. Find the plugin documentation here

Also, you can try doing this. There is a section in second hyperlink which shows how to configure docker agent before you use it.

Hope this helps, Have a great day.

  • Thanks for the response. I agree with what you are saying, however that was not the issue I was facing. There is a docker-in-docker container that is running on the same network as my Jenkins container, both container are in the same docker-compose file. My Jenkins container could not send docker commands to the daemon, which is in the docker-in-docker container. I had to configure the service name that is running the docker-in-docker container in my docker-compose so that it matches the URL that the docker client in the Jenkins is trying to reach. Hope that makes sense. Thanks for your help. – mogale Nov 04 '22 at 17:43
  • Would this answer be relevant to your setup? https://stackoverflow.com/a/49312179/1659807 – duykhoa Aug 21 '23 at 13:17
0

I just faced the same problem, well everything was going good till I removed the docker:dind container, and after when I want to to exucute a pipeline l got an error

error during connect: get "https://docker:2376/v1.24/containers/node:16-alpine/json": dial tcp: lookup docker on 127.0.0.11:53: server misbehaving

I didn't know whats wrong and after 1 day of researching and reading this https://www.jenkins.io/doc/book/installing/docker/, I recognize that I must run docker:dind container.

helvete
  • 2,455
  • 13
  • 33
  • 37