Martin Thoma
Martin Thoma

Reputation: 136715

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?

Upvotes: 1

Views: 926

Answers (2)

François Perin
François Perin

Reputation: 46

You can also write string bash command suround with back quote to execute it.

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

Upvotes: 1

mohit
mohit

Reputation: 2469

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}

Upvotes: 2

Related Questions