LogIn
I don't have account.

How to Install and Run Docker on Amazon EC2 by yum

DevSniper
194 Views

Amazon EC2 (Elastic Compute Cloud) is a web service that provides resizable compute capacity in the cloud. Running Docker on Amazon EC2 allows you to easily deploy, manage and scale Docker containers. In this article, we will walk through, how to install Docker on an Amazon EC2 instance using the yum package manager.

1. Update Linux System

Before installing Docker on machine. Let's first update our machine

sudo yum update -y
2. Install most recent Docker

Now, you can install Docker using yum. Amazon Linux 2 provides Docker directly in its default repositories. To install Docker, use the following command

sudo yum install docker
it will ask you for installation. enter `y`

This will install Docker and all necessary dependencies on your EC2 instance.

3. Start Docker

After installation of Docker, you need to start the Docker service and enable it to start automatically on boot.

To start the Docker service

sudo service docker start
         OR
sudo systemctl start docker

To start Docker automatically on boot

sudo systemctl enable docker

This ensures Docker starts on system reboot.

4. Check Docker running status

To check the current status of the Docker service run below command

sudo service docker status

Some Other Docker Commands

  • docker --version
  • sudo usermod -aG docker ec2-user
  • docker run <container-name>
  • docker run -d -p 80:80 nginx
  • docker stop <container_id> : stop the container
  • docker rm <container_id> : remove the container