Search This Blog

Monday 28 June 2021

Install Docker on an Amazon EC2 instance

Docker is a technology that provides the tools for you to build, run, test, and deploy distributed applications that are based on Linux containers. 

To install Docker on an Amazon EC2 instance


Launch an instance with the Amazon Linux 2 or Amazon Linux AMI (ignore this step if you already have set up  EC2 instance

  1. Connect to your instance -- using ssh

  2. Update the installed packages and package cache on your instance - using the following command
    sudo yum update -y

  3. Install the most recent Docker Engine package - using the following command
    sudo yum install docker

  4. Start the Docker service - using the following command
    sudo service docker start

  5. Add the ec2-user to the docker group so you can execute Docker commands without using sudo. - using the following command
    sudo usermod -a -G docker ec2-user

  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.

  7. Verify that the ec2-user can run Docker commands without sudo.   - using the following command
    docker info 

  8. Verify that Docker Engine is installed correctly by running the hello-world image --  - using the following command
    docker run hello-world