ECR + AWS App Runner: Step by Step

1. Prerequisite

Make sure you have Docker Desktop installed.

Warning

The homebrew version ofdocker-compose requires virtualbox, and will not work on Apple Silicon computers.

Ensure aws-cli is installed and configured

brew install awscli
aws configure

You’ll need your account_key_id & secret_access_key from the AWS console.

Log docker client into AWS ECR with aws ecr get-login-password --region __region__ | docker login --username AWS --password-stdin __aws_account_id__.dkr.ecr.__region__.amazonaws.com

For example:

aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin xxxxxxxxxxx.dkr.ecr.eu-west-1.amazonaws.com

2. Set up ECR

Create your private repository for your project in the AWS console, and note down the repository_name.

3. Build Your Application

Build the Docker image

docker build .

Tag the local Docker image with the ECR repository name & tags using: docker tag __IMAGE ID__ __aws_account_id__.dkr.ecr._region_.amazonaws.com/__repository_name__:__tag__

For example:

docker tag xxxxxxxxx xxxxxxxxx.dkr.ecr.eu-west-1.amazonaws.com/the-app-that-will-blow-your-socks-off:0.0.11

4. Push Dockerised Application to ECR Repository

Push the images to ECR using docker push __repository__:__tag__

docker push xxxxxxxxxxx.dkr.ecr.eu-west-1.amazonaws.com/the-app-that-will-blow-your-socks-off:0.0.11

Verify that the docker image is pushed to ECR from the AWS console

5. Run Application w/ App Runner

Head to the App Runner Console once the Docker image is up in ECR. Make sure you choose the same region as the ECR. You should be able to find the image from the dropdown if you have selected the same AWS region.

Following the Creating App Runner Service step-by-step guide.

Local Development with docker compose

docker compose --env-file ./.env.local up

Troubleshooting

AWS ECS/ECS exec /usr/local/bin/docker-entrypoint.sh: exec format error

If you build your docker image on an Apple M1/M2 machine, this error may occur. To fix the issue, use:

FROM --platform=linux/amd64 node:lts-alpine
 
# Insdead of the standard `FROM node:lts-alpine`