How to Install Docker on AWS EC2 with Ubuntu(18.04 LTS)

In this blog post we will see how to install docker on AWS EC2 machine.

First, we need to create an EC2 instance from AWS. Then we need to log in to the EC2 machine and then install Docker. Once it is installed, then we can pull any image and run that image on the docker that later becomes a container. I have performed this on Windows.

Pre-requisite:

  • We need an AWS Free tier account as part of this. If you do not have it then check here.
  • Gitbash or putty terminal should be installed in the system

Creation of EC2 Instance

Let us create the EC2 instance first as below

Login to AWS Management Console->EC2 Dashboard->Instances->Launch Instance as below

Search for ubuntu in the search bar ,Select the free tier instance as below

Now, we need to select the hardware requirements for the instance. Click on the free tier t2.micro Type

Now we need to select the details like number of instances, network, subnet etc. Here I a using the default VPC and subnet.After this,click on Next: Add Storage button as below

Add the storage details if require. By default root volume will get 8 GB size which is enough for this demo purpose.

Tags are the metadata that we need to provide in the form of Key, value pair. For example we can provide Environment=Dev.

We can create a new Security group or select an existing group that defines the inbound and outbound traffic that is required for the instance. Here I have enabled all traffic.

In Step 7, review all the information and then Launch.

Now we need to create a key pair, Download the key pair pem file and save it in a particular location.

At this stage, the name of the instance is not created.So give a name to the instance like DockerHosted_Instance as shown below.

Connecting to the EC2 Instance from SSH client

To connect to the EC2 instance via the gitbash terminal , we need to have gitbash installed in the system.We can do the same with the help of putty terminal as well.Go to the connect tab and click on SSH client and copy the highlighted command.

Open the gitbash terminal from the folder where the pem file is stored as below and paste the command as shown below.

This will ask whether to continue connecting or not , Specify yes as below.

Installation of Docker

Go to page get.docker.com and execute the below commands from the ubuntu terminal

# This script is meant for quick & easy install via:
#   $ curl -fsSL https://get.docker.com -o get-docker.sh
#   $ sh get-docker.sh

Docker has been installed successfully.

Leave a Comment