嗨,我正在为詹金斯工作。我正在尝试将图像推送到ECR。我正在使用本地docker构建映像。下面是我的詹金斯文件。
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....'
}
}
}
}
在上面的代码中,我能够构建和创建图像。在第二阶段,我面临的问题。我遇到错误了。
$ 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
有人可以帮助我解决此问题吗?任何帮助,将不胜感激。谢谢
答案 0 :(得分:1)
docker.io
的默认存储库是hardcode
:docker.io/library/
因此对于AWS ECR存储库,您应该:
docker build -t test-repository .
docker标签test-repository:latest 536703334988.dkr.ecr.ap-southeast-2.amazonaws.com/test-repository:latest
docker push 536703334988.dkr.ecr.ap-southeast-2.amazonaws.com/test-repository:latest
确保test-repository
回购已在ECR上创建。