简体   繁体   English

将 Docker 镜像上传到 AWS ECR

[英]Uploading Docker Images to AWS ECR

I am trying to create a workflow where developers in my organisation can upload docker images to our AWS ECR.我正在尝试创建一个工作流,我组织中的开发人员可以将 docker 图像上传到我们的 AWS ECR。 The following commands work :以下命令有效:

Step-1: Get Token步骤 1:获取令牌

aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <repo-url>

Step-2: Tag the already built image步骤 2:标记已经构建的镜像

docker tag <local-image:tag> <ecr-repo-url>:latest

Step-3: Finally Push第 3 步:最后推送

docker push <ecr-repo-url>:latest

Now this works absolutely fine.现在这工作得很好。

However as I am trying to automate the above steps.然而,当我试图自动化上述步骤时。 I will NOT have AWS CLI configured on end users machine .我不会在最终用户机器上配置 AWS CLI So Step-1 will fail for the end user因此,对于最终用户而言,第 1 步将失败

So two quick queries:所以两个快速查询:

  1. Can I get the token from a remote machine and Step-2 and Step-3 can happen from client我可以从远程机器获取令牌吗,并且步骤 2 和步骤 3 可以从客户端发生
  2. Can I do all the three steps in remote and I have a service that uploads the local docker image to the remote server which in turn will take care of tag - push我可以在远程完成所有三个步骤吗,我有一个服务可以将本地 docker 镜像上传到远程服务器,而远程服务器又会处理标签 - 推送

I'm hoping that the end-user will have docker installed我希望最终用户安装 docker

In that case you can make use AWS CLI docker image to obtain the token from ECR.在这种情况下,您可以使用AWS CLI docker 映像从 ECR 获取令牌。

The token itself is just a temporary password so whether you use the AWS CLI on the remote server or not it will be valid for the Docker credentials.令牌本身只是一个临时密码,因此无论您是否在远程服务器上使用 AWS CLI,它都对 Docker 凭证有效。

You of also have the option of using the AWS SDK that you could package with a small application to perform this action, such as Boto3 although you would need to ensure that the host itself has the relevant programming language configured.您还可以选择使用 AWS 开发工具包,您可以将其与小型应用程序一起打包来执行此操作,例如Boto3,但您需要确保主机本身配置了相关的编程语言。

Alternatively if you want this to be automated you could actually look at using a CI/CD pipeline.或者,如果您希望实现自动化,您实际上可以考虑使用 CI/CD 管道。

GitHub has Actions , BitBucket has Pipelines and GitLab has arguably the most CI/CD built into it. GitHub 有Actions ,BitBucket 有Pipelines ,而 GitLab 可以说是内置了最多CI/CD 的 This would have these services perform all of the above actions for you.这将使这些服务为您执行上述所有操作。

As a final suggestion you could use CodeBuild within a CodePipeline to build your image and then tag and deploy it to ECR for you.作为最终建议,您可以在CodePipeline 中使用CodeBuild来构建您的映像,然后为您标记并将其部署到 ECR。 This will be automated by a trigger and not require any permanent infrastructure.这将通过触发器自动执行,不需要任何永久性基础设施。

More information about this option is available in the Build a Continuous Delivery Pipeline for Your Container Images with Amazon ECR as Source article.有关此选项的更多信息,请参阅使用 Amazon ECR 作为源为您的容器映像构建持续交付管道一文。

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

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