Search code examples
amazon-web-servicesamazon-ecs

building a docker image in AWS with CLI


I was using gcloudbefore and could build a docker image on a GCP machine as follows:

gcloud builds submit ./my-docker-dir/ -t eu.gcr.io/<path>/<component>:<tag> --timeout 30m --machine-type e2-highcpu-32\n

Is there a similar AWS equivalent?


Solution

  • No, there's no such alternative. With AWS you use docker to build & push to ECR.

    An example workflow would be:

    1. Create a docker file and build it with:
    docker build -t hello-world .
    
    1. Authenticate your Docker client to the Amazon ECR registry to which you intend to push your image.
    aws ecr get-login-password --region region | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com
    
    1. Create an ECR repository
    aws ecr create-repository \
        --repository-name hello-world \
        --image-scanning-configuration scanOnPush=true \
        --region region
    
    1. Tag the docker image you've built.
    docker tag hello-world:latest aws_account_id.dkr.ecr.region.amazonaws.com/hello-world:latest
    
    1. Push it to your ECR repo.
    docker push aws_account_id.dkr.ecr.region.amazonaws.com/hello-world:latest