Rebuild docker image and push to AWS ECR

Table of Content
  1. Login to docker

    docker login
  2. Login to AWS ECR (try skip this step)

    AWS_PROFILE=terraform $(aws ecr get-login --no-include-email --region eu-central-1)

    NOTE. Command above should automatically login to AWS ECR, if it isn’t true, you should try to run command without $(...), just

    AWS_PROFILE=terraform aws ecr get-login --no-include-email --region eu-central-1

    Then copy and past output to CLI

  3. Run docker build

    docker build --no-cache -t tb/web -f .docker/php/Dockerfile .

    --no-cache option can be omitted.
    -f option point the path to Dockerfile
    . dot at the end is required

  4. Create repository (Optional)

    aws ecr create-repository --repository-name tb/web

The response back from the CLI should look something like this:

  "repository": {
    "registryId": "<aws-account-id>",
    "repositoryName": "tb/web",
    "repositoryArn": "arn:aws:ecr:eu-central-1:<aws-account-id>:repository/tb/web",
    "createdAt": 1514064542.0,
    "repositoryUri": "<aws-account-id>"
  1. Create tag (Optional)

    docker tag tb/web <aws-account-id>
  2. Authenticate Docker to an Amazon ECR registry

    $(aws ecr get-login --no-include-email --region eu-central-1)
  3. Push docker image to AWS

    docker push <aws-account-id>

Leave a Reply

Your email address will not be published. Required fields are marked *