AWS Application Deployment Basics: Docker Containers


In the previous couple of posts on this collection, we deployed and ran a few purposes on our EC2 based mostly infrastructure. Right here is how our structure at present seems from the earlier publish:

Current Architecture to Begin Article

Our purposes are working in a personal subnet and NGNIX working as a reverse proxy is permitting entry over the web.

Right this moment, we’ll simply run one more .NET core software on the identical personal EC2 occasion. Identical to within the earlier publish, we’ll serve this software utilizing NGNIX. Nevertheless, this time software will probably be working as a Docker container.

Docker on Ubuntu

Docker is a superb device to simplify software improvement and working. We is not going to go into the small print of Docker or container know-how. I’m assuming you already know the fundamentals of Docker. If you’re new to this matter, there are an awesome many sources out there on-line and I additionally wrote few posts and a ebook on this matter, which you’ll examine.

AWS gives providers to run Docker, e.g., ECS, EKS. It additionally gives AMIs with Docker put in. A few choices there to start out with Docker, nevertheless, we’ll set up and apply it to our EC2 occasion within the personal subnet.

Docker set up is roofed in nice element on the official Docker web site. DigitialOcean additionally has a pleasant article about how one can set up Docker on Ubuntu. You’ll be able to examine it on this hyperlink. Following are instructions to put in Docker on Ubuntu:

sudo apt replace 
sudo apt set up apt-transport-https ca-certificates curl software-properties-common 
curl -fsSL | sudo apt-key add - 
sudo add-apt-repository "deb [arch=amd64] focal secure" 
sudo apt replace 
apt-cache coverage docker-ce 
sudo apt set up docker-ce

As soon as Docker is put in on Ubuntu, you’ll be able to examine the set up standing utilizing the next command: 

sudo systemctl standing docker

Docker Installation Status

Permission for the Present Consumer

Subsequent, I attempted to execute the docker pictures command and it reveals an error relating to permissions:

Docker Images Permission Denied

Let’s add the present person to the Docker group, so I can run Docker instructions with out sudo:

sudo usermod -aG docker ubuntu

Now, re-login to EC2 for this to take impact and as soon as once more attempt the Docker pictures command: 

Trying Docker Images Command Again

For the applying, I’ve a .NET Core undertaking from considered one of my earlier articles and I’ve cloned the repository for the LocalLogin undertaking on my Ubuntu EC2 occasion. cd into the undertaking listing and it incorporates a really primary Dockerfile as proven beneath:

Basic Dockerfile

Subsequent, I construct the Docker picture:

docker picture construct -t locallogin .

Right here is the picture construct course of:

Docker Image Build Process

As soon as the picture is constructed, we will merely run the container from it:

docker run -d --rm --name locallogin -p 6000:5000 locallogin

And it’ll begin our container in indifferent mode. Now if I take advantage of CURL to entry the API:

curl localhost:6000/api/weatherforecast

Application Is Running

You’ll be able to see that our software is working and we will entry the information.

Configure NGNIX

Identical to within the earlier publish. Open the NGNIX configuration file on the Public EC2 occasion. Add a location block for the netcore software container, save and restart NGINX

sudo nano /and so on/nginx/nginx.conf

Adding a Location Block

sudo service nginx restart

As a result of NGINX webserver might be reached from anyplace on the planet (as a consequence of our configs) :

Application is Working As Expected

The applying is working as anticipated.


Right here is the up to date view of EC2 cases and purposes:

Updated View of EC2 Instances and Applications


Docker simplifies software supply, set up, and execution. On this publish, we put in Docker on the EC2 occasion, configured permissions, and spin a .NET core software container. We additionally noticed that wiring up with the NGINX course of is easy. Let me know in case you have any questions or feedback. Until subsequent time, Blissful Coding!

Supply hyperlink


Check Also

Galaxy Unpacked August 2021: Official Trailer

Change is the one fixed on the earth of innovation. By driving new concepts ahead …

Leave a Reply

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