社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  docker

在ecs上运行ecr的docker镜像

Dean Schulze • 5 年前 • 467 次点击  

我在ECR有一个码头工人的形象。我想在云服务器上运行它。我遵循了AWS文档中的步骤 here . 这需要经过一系列的步骤来建立某种类型的ecs集群,但是它从不询问我要在ecr中运行哪个docker映像。

运行Docker映像非常简单,但是对于我要做的事情(运行一个简单Web服务的Docker映像),ecs似乎过于复杂。 This 是我找到的最好的解释。也许我错过了什么。

亚马逊的文档似乎偏离了正题,再也回不到ECR的Docker图像。有没有更好的解释如何在ecs中运行ecr映像?

编辑:添加任务定义json:

{
  "ipcMode": null,
  "executionRoleArn": "arn:aws:iam::504084722442:role/ecsTaskExecutionRole",
  "containerDefinitions": [
    {
      "dnsSearchDomains": null,
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/ecs/first-run-task-definition",
          "awslogs-region": "us-east-2",
          "awslogs-stream-prefix": "ecs"
        }
      },
      "entryPoint": [
        "sh",
        "-c"
      ],
      "portMappings": [
        {
          "hostPort": 80,
          "protocol": "tcp",
          "containerPort": 80
        }
      ],
      "command": [
        "/bin/sh -c \"echo '<html> <head> <title>Amazon ECS Sample App</title> <style>body {margin-top: 40px; background-color: #333;} </style> </head><body> <div style=color:white;text-align:center> <h1>Amazon ECS Sample App</h1> <h2>Congratulations!</h2> <p>Your application is now running on a container in Amazon ECS.</p> </div></body></html>' >  /usr/local/apache2/htdocs/index.html && httpd-foreground\""
      ],
      "linuxParameters": null,
      "cpu": 256,
      "environment": [],
      "resourceRequirements": null,
      "ulimits": null,
      "dnsServers": null,
      "mountPoints": [],
      "workingDirectory": null,
      "secrets": null,
      "dockerSecurityOptions": null,
      "memory": null,
      "memoryReservation": 512,
      "volumesFrom": [],
      "image": "504084722442.dkr.ecr.us-east-2.amazonaws.com/dean.w.schulze.5040",
      "disableNetworking": null,
      "interactive": null,
      "healthCheck": null,
      "essential": true,
      "links": [],
      "hostname": null,
      "extraHosts": null,
      "pseudoTerminal": null,
      "user": null,
      "readonlyRootFilesystem": null,
      "dockerLabels": null,
      "systemControls": null,
      "privileged": null,
      "name": "sample-app"
    }
  ],
  "placementConstraints": [],
  "memory": "512",
  "taskRoleArn": null,
  "compatibilities": [
    "EC2",
    "FARGATE"
  ],
  "taskDefinitionArn": "arn:aws:ecs:us-east-2:504084722442:task-definition/first-run-task-definition:2",
  "family": "first-run-task-definition",
  "requiresAttributes": [
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.execution-role-ecr-pull"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.task-eni"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.ecr-auth"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.execution-role-awslogs"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
    }
  ],
  "pidMode": null,
  "requiresCompatibilities": [
    "FARGATE"
  ],
  "networkMode": "awsvpc",
  "cpu": "256",
  "revision": 2,
  "status": "ACTIVE",
  "volumes": []
}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38139
 
467 次点击  
文章 [ 1 ]  |  最新文章 5 年前
bot
Reply   •   1 楼
bot    6 年前

我知道,当您谈论如何在ecs上运行docker image时,没有什么困惑。我列出了一些关键的概念,这将使您的云服务器容易。

集群 :要在AWS上使用ecs,首先需要创建集群。创建集群很简单,因为您只需在以下两种主要模板类型中进行选择。

  • EC2 :此群集只能运行配置为在EC2实例上运行映像的任务定义。这就像创建一个EC2实例并在上面运行一个Docker映像。
  • 黑洞拦截 :在fargate集群中,不会创建EC2实例,而是只在EC2服务上创建网络接口。您仍然可以根据任务定义分配公共IP并查看容器映像。

任务定义 :您可以将任务定义视为定义容器映像的位置。此任务定义用于在群集中运行任务。您可以在任务定义中定义与Docker映像相关的所有内容,即可以使用的任何内容 docker run 命令,可以在任务定义中配置。

服务 :服务使用任务定义来运行任务。例如,您有一个Docker映像,并且您希望至少有两个实例始终运行您的映像。您可以在将服务配置为2的同时设置实例数,ECS服务将确保两个任务始终在集群内运行您的镜像。如果某个任务由于某种原因停机,它将继续尝试运行您的任务。

任务 :任务是ecs中实际运行docker镜像的实体。可以使用服务或直接创建新任务来生成任务。在这两种情况下,您必须有一个任务定义,其中包含有关Docker映像的信息。

回答您的意见:

“我想我必须编辑容器定义而不是任务定义” .

容器定义就是任务定义。如果要更新图像,可以创建任务定义的新修订,并使用此修订运行任务。如果通过服务运行任务,则可以更新服务并分配最新的任务定义。服务将自动生成具有最新任务定义的新任务。要使用ECR图像,只需从图像名称旁边的图标复制URL,并将其粘贴到任务定义中的“图像”下。

注释 :您应该启用公共IP和/或与实例(ec2)/网络接口(fargate)的Internet连接,以连接到ecr,读取 here .