Learn how to deploy a simple website to AWS App Runner using Docker and NGINX. This project walks you through the steps, from image creation to deployment.
If you want to start deploying your containers to Kubernetes, especially on AWS EKS, check this course on Kubernetes that walkthrough creating Kubernetes cluster on AWS EKS using Terraform and deploying multiple related containers applications to Kubernetes and more. https://www.devteds.com/kubernetes-course-aws-eks-terraform
Visit https://devteds.com to watch all the videos and courses on DevOps and Cloud courses.
git clone
cd docker-on-aws-apprunner
cp .devcontainer/devcontainer.example.json .devcontainer/devcontainer.json
# Edit .devcontainer/devcontainer.json to update .aws path
# Edit aws/apprunner-nginx-service.yml and update ECR image repo:tag
If you don't use VS-Code and you may either use the devcontainer cli or other container alternatives or you just use the CLIs installed on your host OS.
And if you're using DevContainer, DevContainers: ReBuild & ReOpen in Container
cd web
docker build -t nginx-website .
# or
# docker build --platform linux/amd64 -t nginx-website .
aws ecr create-repository --repository-name nginx-ws
docker tag nginx-website <AWS_ACCOUNT_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com/nginx-ws:v1
aws ecr get-login-password --region <AWS_REGION> | docker login --username AWS --password-stdin <AWS_ACCOUNT_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com
docker push <AWS_ACCOUNT_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com/nginx-ws:v1
Got to the root of the project folder.
aws iam create-role --role-name demo-apprunner-role --assume-role-policy-document file://$PWD/aws/trust-policy.json
aws iam create-policy --policy-name demo-apprunner-ecr-policy --policy-document file://$PWD/aws/apprunner-ecr-policy.json
aws iam attach-role-policy --role-name demo-apprunner-role --policy-arn arn:aws:iam:<AWS_ACCOUNT_ID>:poilcy/demo-apprunner-ecr-policy
Update the aws/apprunner-nginx-service.yml for
SourceConfiguration > ImageRepository > ImageIdentifier:
<AWS-ACCOUNT-ID>
,<AWS-REGION>
SourceConfiguration > AuthenticationConfiguration > AccessRoleArn:
<AWS-ACCOUNT-ID>
aws apprunner create-service --cli-input-yaml file://$PWD/aws/apprunner-nginx-service.yml
aws apprunner list-services
Use the ServiceUrl
from the aws apprunner list-services
response to hit the app on browser and verify.
- Delete the App Runner service
aws apprunner delete-service --service-arn <SERIVE_ARN>
- Delete the role & policy
- Delete the ECR repository
Chandra Shettigar | Devteds
- Website: https://devteds.com
- LinkedIn: https://www.linkedin.com/in/shettigarc
- MacOS, Apple M1 chip
- Docker 24.0.2, build cb74dfc
- Docker Compose version v2.18.1
- VSCode 1.87.2 (Universal)
- aws-cli/2.16.4