Setup EC2 instance

I suggest you to select latest Amazon Linux AMI and use default settings to create a new Linux EC2 instance

Note: Please remember to allow port 80 in security groups settings while creating the instance so that we can access the ‘nginx’ website we install at the end of this article

Install and configure Docker

Once your instance is ready to use, connect via SSH to the server

I prefer to do a sudo su and yum update

[ec2-user@ip-172-31-18-62 ~]$ sudo su
[root@ip-172-31-18-62 ec2-user]# yum update

Install docker with the following command

[root@ip-172-31-18-62 ec2-user]# yum install -y docker

Once the installation is completed, start the docker service as below:

[root@ip-172-31-18-62 ec2-user]# service docker start

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

[root@ip-172-31-18-62 ec2-user]# sudo usermod -aG docker ec2-user

To verify that docker is correctly installed, just type a docker ps/info command:

[root@ip-172-31-18-62 ec2-user]# docker ps

[root@ip-172-31-18-62 ec2-user]# docker info

The above commands will show you the version of docker you just installed

Deploy Docker Container

We will create an nginx container with this command:

[root@ip-172-31-18-62 ec2-user]# docker run -d -p 80:80 –name nginx nginx

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:



No responses yet

Leave a Reply

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

Recent Comments