简体   繁体   中英

How can I automatically put a container on AWS ECS?

I currently use the following procedure to put a docker container to ECS:

  1. Execute aws ecr get-login --profile tutorial
  2. Paste the returned stuff in the following shell script

The shell script which creates the container

# 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. Can I somehow execute aws ecr get-login --profile tutorial and execute the returned command (with sudo) automatically?

Yes, You may use the eval to execute docker login command.

For Example:

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

Sample Shell script in your case would be like:

#!/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`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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