简体   繁体   English

如何自动将容器放在AWS ECS上?

[英]How can I automatically put a container on AWS ECS?

I currently use the following procedure to put a docker container to ECS: 我目前使用以下过程将docker容器放入ECS:

  1. Execute aws ecr get-login --profile tutorial 执行aws ecr get-login --profile tutorial
  2. Paste the returned stuff in the following shell script 将返回的内容粘贴到以下shell脚本中

The shell script which creates the container 用于创建容器的shell脚本

# Returned by the command in (1)
sudo docker login -u AWS -p looooong -e none https://foobar.dkr.ecr.us-east-1.amazonaws.com

# Remaining steps
sudo service docker restart

sudo docker build  -t ${image} .
sudo docker tag ${image} ${fullname}

sudo docker push ${fullname}

My question: 我的问题:

Currently, I just the sudo docker login ... line every time manually. 目前,我只是sudo docker login ...每次手动sudo docker login ... Can I somehow execute aws ecr get-login --profile tutorial and execute the returned command (with sudo) automatically? 我可以以某种方式执行aws ecr get-login --profile tutorial并自动执行返回的命令(使用sudo)吗?

Yes, You may use the eval to execute docker login command. 是的,您可以使用eval执行docker login命令。

For Example: 例如:

eval $(aws ecr get-login --no-include-email --region us-west-2)

Sample Shell script in your case would be like: 您的案例中的示例Shell脚本将如下所示:

#!/bin/bash
eval $(aws ecr get-login --no-include-email --region us-west-2)
# Remaining steps
sudo service docker restart

sudo docker build  -t ${image} .
sudo docker tag ${image} ${fullname}

sudo docker push ${fullname}

您还可以使用反向引号编写字符串bash命令,以执行它。

`aws ecr get-login --no-include-email --region us-west-2`

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

相关问题 如何使用AWS CodePipeline更新ECS上的容器服务 - How can I use AWS CodePipeline to update a container service on ECS 如何从 AWS ECS 上的容器中检索私有 IP? - How can I retrieve private IP from a container on AWS ECS? 如何在AWS ECS docker容器中获取AWS凭据? - How do I get AWS credentials in the AWS ECS docker container? 如何使用 Fargate 在 AWS ECS 中正在运行的容器中运行命令 - How can I run commands in a running container in AWS ECS using Fargate 如何为在 AWS ECS 中运行的 Docker 容器配置“ulimits”? - How do I configure "ulimits" for a Docker container running in AWS ECS? How can I call Lambda function from MySQL database in AWS and how can I pass a parameter to a container in ECS from the Lambda function? - How can I call Lambda function from MySQL database in AWS and how can I pass a parameter to a container in ECS from the Lambda function? AWS ECS容器无法指定区域 - AWS ECS container can't specify a region 如何让 AWS ECS 自动将我的容器的端口映射到主机(EC2) - How to have AWS ECS automatically map ports of my container to the host machine(EC2) 如何将文件密钥传递给在 S3 Put 上触发的 AWS-ECS 容器? - How to pass file key to AWS-ECS container triggered on S3 Put? 如何在ECS上自动启动我的docker容器? - How to launch my docker container automatically on ECS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM