【问题标题】:How to look for a docker image on the local machine如何在本地机器上查找 docker 镜像
【发布时间】:2018-03-16 14:10:23
【问题描述】:

我的本​​地机器上有一个 docker 映像。当我尝试使用下面的 Jenkins 文件运行映像时。

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

然后我收到以下错误。

+ docker pull gcc/sample:latest

Pulling repository docker.io/gcc/sample

Error: image gcc/sample:latest not found

script returned exit code 1

我有什么办法可以在 Jenkins 文件中说在我的本地机器上查找 docker 映像而不是 docker.io 来查找 docker 映像。

【问题讨论】:

  • jenkins 是在 docker 容器中运行,还是直接在机器上运行?
  • Jenkins 直接在 Linux 机器上运行。
  • 图片gcc/sample:latest在本地找到了吗?使用标签 latest 运行 docker image ls 时会出现吗?
  • 该图像在本地存在,但是当我使用上面的 Jenkins 文件(图像'gcc/sample:latest')时,它并没有在本地查找。它只在 repo 中查找。

标签: docker jenkins-plugins dockerfile jenkins-pipeline docker-machine


【解决方案1】:

为此,您需要在本地机器或运行 Jenkins 的 Jenkins 服务器上安装 docker 注册表。 只需运行 docker 注册表容器

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

首先标记您的图像

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

将该图像推送到您的本地 docker 注册表

docker push localhost:5000/gcc/sample:latest

现在,如果您想在 jenkins 中拉取该 docker 映像,请提供带有 dns 的拉取路径,因为我们从 docker 注册表中拉取一些东西,它包含带有 dns 的全名。

docker pull localhost:5000/gcc/sample:latest

注册表是一个存储和内容交付系统,包含命名的 Docker 映像,可用于不同的标记版本。

docker pull ubuntu 指示 docker 从官方 Docker Hub 拉取一个名为 ubuntu 的镜像。这只是更长的 docker pull docker.io/library/ubuntu 命令的快捷方式

docker pull myregistrydomain:port/foo/bar 指示 docker 联系 位于 myregistrydomain:port 的注册表以查找图像 富/酒吧

运行您自己的注册表是一个很好的解决方案,可以集成并 补充您的 CI/CD 系统。

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

【讨论】:

    【解决方案2】:

    原来这已经是一个已知问题:https://issues.jenkins-ci.org/browse/JENKINS-47106

    docker 镜像总是在代理定义中拉取。目前唯一的解决方案是将镜像推送到 Dockerhub 或私有注册表,以便成功拉取。

    【讨论】:

      【解决方案3】:

      在我们的环境中,由于某种原因,使用并行阶段会阻止拉动操作。

      #!/usr/bin/env groovy
      pipeline {
          agent none
      
          options {
              timestamps()
          }
      
          stages {
              stage('Parallel') {
                  parallel {
                      stage('EL6') {
                          agent { 
                              docker { 
                                  image 'centos6'
                                  label 'Docker&&EL'
                              }
                          }
                          steps {
                              ...
                          }
                      }
                  }
              }
          }
      }
      

      背景:我们通常使用具有并行步骤的多分支流水线作业。在测试新东西时,我写了一个使用 docker 的最简单的 Jenkinsfile。我使用了一个没有并行部分的简单管道作业,并注意到它总是尝试拉动(并且失败)。

      相关插件:

      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
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-10
        • 2021-05-27
        • 2018-08-28
        • 2022-01-26
        • 2018-09-14
        • 2015-01-28
        • 2021-07-05
        • 2017-11-30
        相关资源
        最近更新 更多