简体   繁体   English

如何将Docker镜像推送到Jenkins中的ECR?

[英]How to push Docker image to ECR in Jenkins?

I am working with Jenkins. I am trying to push image to ECR .我正在使用 Jenkins。我正在尝试将图像推送到ECR I am using local Docker to build the images.我正在使用本地 Docker 来构建图像。

Below is my Jenkins file:下面是我的 Jenkins 文件:

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                bat  'docker build -t sampleapp -f SampleApp/Dockerfile .'
            }
        }
        stage('Push image') {
         steps {
           withDockerRegistry([url: "https://536703334988.dkr.ecr.ap-southeast-2.amazonaws.com/test-repository",credentialsId: "ecr:ap-southeast-2:demo-ecr-credentials"]) {
           bat 'docker push sampleapp:latest'
               }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying....'
            }
        }
    }
}

In the above code, I am able to build and create an image.在上面的代码中,我能够构建和创建图像。 In the second stage, I am facing the issues.在第二阶段,我面临的问题。 I am getting the below error:我收到以下错误:

 $ docker login -u AWS -p ******** https://536703334988.dkr.ecr.ap-southeast-2.amazonaws.com/test-repository WARNING. Using --password via the CLI is insecure. Use --password-stdin: Login Succeeded C:\Program Files (x86)\Jenkins\workspace\SampleAppPipeLine>docker push sampleapp.latest The push refers to repository [docker:io/library/sampleapp] a160522d6d0e: Preparing 2e2c2606bd45: Preparing 9b0a482c69b1: Preparing 995a0cc6a5f6: Preparing c1b55dcb46c2: Preparing cf5b3c6798f7: Preparing cf5b3c6798f7: Waiting denied: requested access to the resource is denied

Can someone help me to fix this issue?有人可以帮我解决这个问题吗? Any help would be appreciated.任何帮助,将不胜感激。
Thanks.谢谢。

Default repository of docker.io is being hardcode is: docker.io/library/ docker.io的默认存储库被hardcode为: docker.io/library/

So for AWS ECR repo, you should:因此,对于 AWS ECR 存储库,您应该:

docker build -t test-repository .

docker tag test-repository:latest 536703334988.dkr.ecr.ap-southeast-2.amazonaws.com/test-repository:latest docker 标签测试存储库:最新 536703334988.dkr.ecr.ap-southeast-2.amazonaws.com/test-repository:最新

docker push 536703334988.dkr.ecr.ap-southeast-2.amazonaws.com/test-repository:latest

Make sure test-repository repo is already create on ECR.确保已在 ECR 上创建test-repository回购。

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

相关问题 关于在Jenkins配置上传docker图片到ECR的问题 - Question about configuring policy for uploading docker image to ECR in Jenkins 即使登录 docker 并成功,也无法将图像推送到 ECR - can't push image to ECR even though login in docker and was successfully 如何在 Githubactions 中从 ECR 中提取 docker 图像 - How to pull docker image from ECR in Githubactions 使用 terraform 构建 docker 映像,将其推送到 ECR 存储库,获取配置程序“local-exec”错误 - Build docker image with terraform push it to ECR repo getting provisioner "local-exec" error 将 Docker 图像从 S3 上传到 ECR - Uploading a Docker Image to ECR from S3 将图像推送到 ECR 仅适用于私有存储库 - Push image to ECR works for private repositories only 如何使用 buildspec.yml 在 AWS CodePipeline 中从 Dockerfile 构建图像,然后推送到 ECR? - How to build Image from Dockerfile in AWS CodePipeline using buildspec.yml, and then push to ECR? Docker 推送到 AWS ECR 立即挂起并超时 - Docker push to AWS ECR hangs immediately and times out 如何在启用 MFA 的情况下将 docker 图像从 AWS ECR 拉到 Minikube Kube.netes 集群 - How to pull a docker image from AWS ECR to Minikube Kubernetes cluster with MFA enabled 如何从 AWS ECR 中提取私有 docker 图像以与 Java 中的 Testcontainers 库一起使用 - How to pull a private docker image from AWS ECR to use with the Testcontainers library in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM