paint-brush
Running Docker on AWS EC2by@mlabouardy
106,350 reads
106,350 reads

Running Docker on AWS EC2

by Mohamed LabouardyAugust 30th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In this quick tutorial, I will show you how to install <strong>Docker </strong>on <strong>AWS EC2</strong> instance and run your first <strong>Docker container</strong>.
featured image - Running Docker on AWS EC2
Mohamed Labouardy HackerNoon profile picture

In this quick tutorial, I will show you how to install Docker on AWS EC2 instance and run your first Docker container.

1 — Setup EC2 instance

I already did a tutorial on how to create an EC2 instance, so I won’t repeat it. There are few ways you’ll want to differ from the tutorial:

  • We select the “Amazon Linux AMI 2017.03.1 (HVM), SSH Volume Type” as AMI. The exact versions may change with time.
  • We configure the security groups as below. This setting allows access to port 80 (HTTP) from anywhere, and SSH access also.

Go ahead and launch the instance, it will take couple of minutes:

2 — Install Docker

Once your instance is ready to use, connect via SSH to the server using the public DNS and the public key:

Once connected, use yum configuration manager to install Docker, by typing the following commands:

sudo yum update -y

sudo yum install -y docker

Next, start the docker service:

In order to user docker command without root privileges (sudo), we need to add ec2-user to the docker group:

sudo usermod -aG docker ec2-user

To verify that docker is correctly installed, just type:

As you can see the latest version of docker has been installed (v17.03.1-ce)

Congratulation ! you have now an EC2 instance with Docker installed.

3 — Deploy Docker Container

It’s time to run your first container

. We will create an nginx container with this command:

If we run the list command “docker ps”, we can see that an nginx container has been created from the nginx official image.

Finally, you visit your instance public DNS name in your browser, you should see something like this below: