How to look for a docker image on the local machine
Asked Answered
A

4

5

I have a docker image on my local machine. When I try to run the image using the below Jenkins file.

agent {
docker {
image 'gcc/sample:latest'
args "-v /etc/passwd:/etc/passwd:ro 
        }
    }

Then I am getting the following error.

+ docker pull gcc/sample:latest

Pulling repository docker.io/gcc/sample

Error: image gcc/sample:latest not found

script returned exit code 1

Is there any way that I can say in Jenkins files to look for docker image at my local machine instead of docker.io for docker image.

Archon answered 16/3, 2018 at 14:10 Comment(4)
Is jenkins running in a docker container, or directly on machine?Harlin
Jenkins is directly running on a Linux machine.Archon
Is the image gcc/sample:latest found locally? Does it appear when you run docker image ls with tag latest?Harlin
The image is present locally but when I use the above Jenkins file (image 'gcc/sample:latest') it is not looking locally. It is only looking in repo.Archon
A
10

For that, you need docker registry on your local machine or on Jenkins server where Jenkins is running. Just run the docker registry container

 docker run -d -p 5000:5000 --restart always --name registry registry:2

First tag your image

docker tag alpine localhost:5000/gcc/sample:latest

push that image to your local docker registry

docker push localhost:5000/gcc/sample:latest

Now if you want to pull that docker images in jenkins so give pull path with dns as we pull some thing from docker registry its contain full name with dns.

docker pull localhost:5000/gcc/sample:latest

A registry is a storage and content delivery system, holding named Docker images, available in different tagged versions.

docker pull ubuntu instructs docker to pull an image named ubuntu from the official Docker Hub. This is simply a shortcut for the longer docker pull docker.io/library/ubuntu command

docker pull myregistrydomain:port/foo/bar instructs docker to contact the registry located at myregistrydomain:port to find the image foo/bar

Running your own Registry is a great solution to integrate with and complement your CI/CD system.

https://docs.docker.com/registry/introduction/

Allo answered 18/3, 2018 at 0:39 Comment(0)
H
0

Turns out that this is already a known issue: https://issues.jenkins-ci.org/browse/JENKINS-47106

The docker image is always pulled inside the agent definition. The only solution in the meantime is to push the image to Dockerhub or a private registery so that it will be successfully pulled.

Harlin answered 16/3, 2018 at 15:39 Comment(0)
A
0

In our environment using parallel stages prevents the pull action for some reason.

#!/usr/bin/env groovy
pipeline {
    agent none

    options {
        timestamps()
    }

    stages {
        stage('Parallel') {
            parallel {
                stage('EL6') {
                    agent { 
                        docker { 
                            image 'centos6'
                            label 'Docker&&EL'
                        }
                    }
                    steps {
                        ...
                    }
                }
            }
        }
    }
}

Background: We typically use Multibranch Pipeline jobs with parallel steps. While testing something new I wrote up the simplest Jenkinsfile that utilizes docker. I used a simple Pipeline job with no parallel section and noticed that it always attempted a pull (and failed).

Relevant plugins:

Docker Commons Plugin
Provides the common shared functionality for various Docker-related plugins.
1.11
Downgrade to 1.11

Docker Pipeline
Build and use Docker containers from pipelines.
1.15

Pipeline: API
Plugin that defines Pipeline API.
2.28
Downgrade to 2.25

Pipeline: Basic Steps
Commonly used steps for Pipelines.
2.6

Pipeline: Declarative
An opinionated, declarative Pipeline.
1.2.7

Pipeline: Declarative Agent API
Replaced by Pipeline: Declarative Extension Points API plugin.
1.1.1

Pipeline: Declarative Extension Points API
APIs for extension points used in Declarative Pipelines.
1.2.7

Pipeline: Job
Defines a new job type for pipelines and provides their generic user interface.
2.17

Pipeline: Model API
Model API for Declarative Pipeline.
1.2.7


Pipeline: Stage Step
Adds the Pipeline step stage to delineate portions of a build.
2.3

Pipeline: Stage Tags Metadata
Library plugin for Pipeline stage tag metadata.
1.2.7

Pipeline: Stage View Plugin
Pipeline Stage View Plugin.
2.9

Pipeline: Step API
API for asynchronous build step primitive.
2.16
Downgrade to 2.14

Pipeline: Supporting APIs
Common utility implementations to build Pipeline Plugin
2.17

Alrich answered 10/1, 2019 at 21:54 Comment(0)
K
0

Under the docker agent template there will be a option "pull strategy". Set it to "never" so that jenkins don't execute the pull command and enter image description heredirectly search for the image in local.

Knothole answered 9/9 at 8:56 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Monohydric

© 2022 - 2024 — McMap. All rights reserved.