How to Install and Run Docker on Amazon EC2 by yum
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.
Before installing Docker on machine. Let's first update our machine
sudo yum update -y
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
This will install Docker and all necessary dependencies on your EC2 instance.
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.
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