Search code examples
amazon-web-servicesdockerpipelineamazon-ecs

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?


Solution

  • 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}