简体   繁体   English

无法将 docker 镜像推送到 artifactory 注册表

[英]Not able to push docker image to artifactory registry

I am not able to push docker image to artifactory registry getting below error我无法将 docker 镜像推送到 artifactory 注册表中,但出现以下错误

Login and pulling works fine登录和拉取工作正常

92bd1433d7c5: Layer already exists
b31411566900: Layer already exists
f0ed7f14cbd1: Layer already exists
851f3e348c69: Layer already exists
e27a10675c56: Layer already exists
EOF

Jenkinsfile:詹金斯档案:

node ('lnp6xxxxxxb003') {
    def app
    def server = Artifactory.server 'maven-qa'
    server.bypassProxy = true

    stage('Clone repository') {
        /* Let's make sure we have the repository cloned to our workspace */

        checkout scm
    }

    stage('Build image') {
        /* This builds the actual image; synonymous to
         * docker build on the command line */

        app = docker.build("devteam/maven")
    }

    stage('Test image') {
        /* Ideally, we would run a test framework against our image.

        app.inside {
            sh 'mvn --version'
            sh 'echo "Tests passed"'
        }
    }

    stage('Push image') {
        /* Finally, we'll push the image with two tags:
         * First, the incremental build number from Jenkins
         * Second, the 'latest' tag.
         * Pushing multiple tags is cheap, as all the layers are reused. */
          docker.withRegistry('https://docker.maven-qa.xxx.partners', 'docker-credentials') {
            app.push("${env.BUILD_NUMBER}")
          /*  app.push("latest") */
        }
    }
}

Dockerfile: Dockerfile:

# Dockerfile

FROM maven

ENV MAVEN_VERSION 3.3.9

ENV MAVEN_HOME /usr/share/maven

VOLUME /root/.m2

CMD ["mvn"]

Not sure what is wrong in that.不知道有什么问题。 I am able to manually push a image on the jenkins slave node.我能够在 jenkins 从节点上手动推送图像。 But using jenkins it gives error但是使用詹金斯它会出错

Logs of my build job我的构建工作的日志

    Logs
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build image)
[Pipeline] sh
[docker-maven-image] Running shell script
+ docker build -t devteam/maven .
Sending build context to Docker daemon 231.9 kB

Step 1 : FROM maven
 ---> 1f858e89a584
Step 2 : ENV MAVEN_VERSION 3.3.9
 ---> Using cache
 ---> c5ff64f9ff9f
Step 3 : ENV MAVEN_HOME /usr/share/maven
 ---> Using cache
 ---> 2a2028d6fdbc
Step 4 : VOLUME /root/.m2
 ---> Using cache
 ---> a50223412b56
Step 5 : CMD mvn
 ---> Using cache
 ---> 2d32a26dde10
Successfully built 2d32a26dde10
[Pipeline] dockerFingerprintFrom
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Push image)
[Pipeline] withDockerRegistry
Wrote authentication to /usr/share/tomcat6/.docker/config.json
[Pipeline] {
[Pipeline] sh
[docker-maven-image] Running shell script
+ docker tag --force=true devteam/maven devteam/maven:84
unknown flag: --force
See 'docker tag --help'.
+ docker tag devteam/maven devteam/maven:84
[Pipeline] sh
[docker-maven-image] Running shell script
+ docker push devteam/maven:84
The push refers to a repository [docker.maven-qa.XXXXX.partners/devteam/maven]
e13738d640c2: Preparing
ef91149a34fb: Preparing
3332503b7bd2: Preparing
875b1eafb4d0: Preparing
7ce1a454660d: Preparing
d3b195003fcc: Preparing
92bd1433d7c5: Preparing
f0ed7f14cbd1: Preparing
b31411566900: Preparing
06f4de5fefea: Preparing
851f3e348c69: Preparing
e27a10675c56: Preparing
92bd1433d7c5: Waiting
f0ed7f14cbd1: Waiting
b31411566900: Waiting
06f4de5fefea: Waiting
851f3e348c69: Waiting
e27a10675c56: Waiting
d3b195003fcc: Waiting
e13738d640c2: Layer already exists
3332503b7bd2: Layer already exists
7ce1a454660d: Layer already exists
875b1eafb4d0: Layer already exists
ef91149a34fb: Layer already exists
d3b195003fcc: Layer already exists
f0ed7f14cbd1: Layer already exists
b31411566900: Layer already exists
92bd1433d7c5: Layer already exists
06f4de5fefea: Layer already exists
851f3e348c69: Layer already exists
e27a10675c56: Layer already exists
EOF
[Pipeline] }
[Pipeline] // withDockerRegistry
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

This is what I have in my build logs.这就是我的构建日志中的内容。

I am using nginx in artifactory as a reverse proxy which is behind load balancer.I removed below lines from nginx config and it worked proxy_set_header X-Artifactory-Override-Base-Url我在 artifactory 中使用 nginx 作为负载均衡器后面的反向代理。我从 nginx 配置中删除了以下几行并且它工作了 proxy_set_header X-Artifactory-Override-Base-Url

$http_x_forwarded_proto://$host/artifactory;
    proxy_set_header X-Forwarded-Port $server_port;
    proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

I am still not sure why these headers causing issue.我仍然不确定为什么这些标题会导致问题。

I have also faced same issue after I enable the Docker pipeline plugin it is started working.在启用 Docker 管道插件开始工作后,我也遇到了同样的问题。 I think it maybe help you https://plugins.jenkins.io/docker-workflow/我认为它可能对你有帮助https://plugins.jenkins.io/docker-workflow/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM