Wednesday, November 3, 2021

How to install Docker on an Amazon EC2 instance

 Pre-Requisites: 1. Create AWS Console account

                           2. Create AWS EC2 instance EC2 Instance creation link

                    

Step 1: Launch an instance with the Amazon Linux 2 or Amazon Linux AMI and connect to EC2 instance using putty

Step 2: Update the installed packages and package cache on your instance.

                $ sudo yum update -y

Step 3: Amazon Linux 2

            $ sudo amazon-linux-extras install docker -y



           Amazon Linux.

            $ sudo yum install docker -y


Step 3: Start the Docker service.

           sudo service docker start

Step 4: Check the docker version 
             $ docker info
Step 5: Add the ec2-user to the docker group so you can execute Docker commands without using sudo.
           sudo usermod -a -G docker ec2-user 


Step 6: Log out and log back in again to pick up the new docker group permissions. You can accomplish this by closing your current SSH terminal window and reconnecting to your instance in a new one. Your new SSH session will have the appropriate docker group permissions.

Step 7: Verify that the ec2-user can run Docker commands without sudo.
             $ docker info 
             $ docker --version
             $ docker images
             $ docker ps -a 
Step 8: Run sample docker image by pulling the hello-world image from docker hub (How to create docker Hub Account)
            $ docker run hellow-world:latest
            





Note
In some cases, you may need to reboot your instance to provide permissions for the ec2-user to access the Docker daemon. Try rebooting your instance if you see the following error:

Cannot connect to the Docker daemon. Is the docker daemon running on this host?




No comments:

Post a Comment

How to install and setup Kubernetes cluster using kOps in AWS environment

  Kops: Kops is also known as Kubernetes Operations, it is an open-source project which helps you to create, upgrade, destroy, and maintain ...