AWS ECR, Docker and .NET Core

Home / AWS ECR, Docker and .NET Core

Over the past weekend, I was playing around with deploying .NET Core Docker images to Amazon AWS. I wanted to utilize their EC2 Container Repository (ECR) to keep everything self-contained. My initial tinkering turned out pretty well. I’ll have a better walk-through once I have everything working as I want.

At any rate, here are a few notes I made to myself for the steps I went through, which I thought I’d share. These steps detail building/deploying Docker containers to AWS using EC2 with the EC2 Container Repository (ECR). Docker images were made directly from VS2017 using Docker CE (Docker Compose).


I ran all of this in a Win10 VM (VMWare) set to machine type of Hyper-V which allows Hyper-V to be enabled in the VM, which is required by Docker CE.

I basically had everything working up to the point of defining the Task / Cluster to run the image (and allow scaling).

I followed instructions here for creating an Instance (up to and including step 5). It was good enough to explain the IAM roles / users / etc.

http://docs.servicestack.net/deploy-netcore-docker-aws-ecs

Created a private ECR Repository.

Set up Putty for SSH access:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html#putty-private-key
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html?icmpid=docs_ec2_console

After the instance/user/security roles were created, I set up AWS CLI:

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
http://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html

The keys needed for the AWS CLI are available under the IAM console:

https://console.aws.amazon.com/iam/home#/users

Installed Docker on the Instance:

http://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html

Account ID is found here:
https://console.aws.amazon.com/billing/home?#/account

I added Docker support to the CSOKI aspnet-core-template project w/ Docker CE set to build Linux images and ran ‘Build’ from VS2017. Afterward, I followed this guide for pushin the image:
http://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html

Retrieve the docker login and everything needed for docker from here (command run from local command prompt):

http://docs.aws.amazon.com/AmazonECR/latest/userguide/ECR_AWSCLI.html

The repository URI is also available here (region specific):

https://us-west-2.console.aws.amazon.com/ecs/home?region=us-west-2#/repositories

Misc commands:

RepoUrl is in the format [accountid].dkr.ecr.[region].amazonaws.com/[ecr-repo-name]

… get ecs login -> aws ecr get-login –no-include-email –region us-west-2
… docker login from prev command….
docker tag [imageid] [repoUrl]
docker push [repourl]

In Putty over SSH to the EC2 instance – to test image:

logged-in via the docker login command (same as above from AWS CLI setup)
docker pull [repoUrl]
docker run -p 80:80 [repoUrl]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.