“最新的"如何标记在ECS任务定义中的工作以及从ECR中提取的容器实例? [英] How does "latest" tag work in an ECS task definition and container instances pulling from ECR?

查看:137
本文介绍了“最新的"如何标记在ECS任务定义中的工作以及从ECR中提取的容器实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ECR任务定义中使用latest标记时遇到问题,其中image参数的值类似于XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/reponame/web:latest.

I'm having problems using latest tag in an ECR task definition, where image parameter has value like XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/reponame/web:latest.

我希望一旦在容器实例(注册到集群的EC2实例)上运行了新的服务实例(任务),此任务定义就会从ECR中提取带有latest标记的图像.

I'm expecting this task definition to pull an image with latest tag from ECR once a new service instance (task) is run on the container instance (an EC2 instance registered to the cluster).

但是,就我而言,当我远程连接到容器实例并列出docker映像时,我可以看到它尚未从ECR中提取最新的发行版映像.

However in my case when I connect to the container instance remotely and list docker images, I can see that it has not pulled the latest release image from ECR.

最新标签比当前版本落后两个发行版本,自从我更新任务定义以来,使用了显式定义版本标签的latest标签实例,即:v1.05.

The latest tag there is two release versions behind the current one, from since I updated the task definition to use latest tag instance of explicitly defining the version tag i.e. :v1.05.

我在这个集群上只有一个容器实例.

I have just one container instance on this cluster.

我的过程中可能会有一些怪癖,但是这个问题主要是关于latest在这种情况下应如何表现的?

It's possible there is some quirk in my process, but this question is mainly about how this latest should behave in this kind scenario?

我的docker映像构建和标记,ECR推送,ECS任务定义更新以及ECS服务更新过程:

My docker image build and tagging, ECR push, ECS task definition update, and ECS service update process:

# Build the image with multiple tags
docker build -t reponame/web:latest -t reponame/web:v1.05 .

# Tag the image with the ECR repo URI
docker tag ${imageId} XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/reponame/web

# Push both tags separately
docker push XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/reponame/web:v1.05
docker push XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/reponame/web:latest

# Run only if the definition file's contents has been updated
aws ecs register-task-definition --cli-input-json file://web-task-definition.json

# Update the service with force-new-deployment
aws ecs update-service \
  --cluster my-cluster-name \
  --service web \
  --task-definition web \
  --force-new-deployment

带有任务定义文件:

{
  "family": "web",
  "containerDefinitions": [
    {
      "name": "web",
      "image": "XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/reponame/web:latest",
      "essential": true,
      "memory": 768,
      "memoryReservation": 512,
      "cpu": 768,
      "portMappings": [
        {
          "containerPort": 5000,
          "hostPort": 80
        }
      ],
      "entryPoint": [
        "yarn", "start"
      ],
      "environment": [
        {
          "name": "HOST",
          "value": "0.0.0.0"
        },
        {
          "name": "NUXT_HOST",
          "value": "0.0.0.0"
        },
        {
          "name": "NUXT_PORT",
          "value": "5000"
        },
        {
          "name": "NODE_ENV",
          "value": "production"
        },
        {
          "name": "API_URL",
          "value": "/api"
        }
      ]
    }
  ]
}

推荐答案

原来的问题出在我的脚本上.正在使用另一个具有旧值的变量,该变量仍存储在我的终端会话中.

Turned out the problem was with my scripts. Was using a different variable that had an old value still stored with my terminal session.

我已经验证,通过在任务定义的图像源url中使用latest标记,确实有一个新启动的服务实例可以从ECR中使用latest标记提取图像.

I've validated that by using latest tag in the task definition's image source url does have a newly started service instance to pull in the image with latest tag from ECR.

无需注册任务定义的新版本.

Without needing to register a new revision of the task definition.

作为附带说明,在处理latest标记时需要格外小心.在这种情况下,它似乎可以解决问题,但在许多其他情况下,则容易出错: Ref1 Ref2

As a sidenote, one needs to be careful with handling the latest tag. In this scenario it seems to work out, but in many other cases it would be error prone: Ref1, Ref2

这篇关于“最新的"如何标记在ECS任务定义中的工作以及从ECR中提取的容器实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆