Docker Engine can be installed easily on Amazon Linux 2 running on AWS Ec2 Instance using Yum package manager. If you don’t know how? Then here are the steps to follow.
Well, being a command-line operating system running on expensive cloud computing services, we need some virtualize platform with lightweight. And what would be better than Docker? There are lots of benefits of using applications virtualized via containers. It improves security and easier management of the software on the server: If an application is hacked, the attacker can only manipulate the container – not the other virtualized applications on the system.
Furthermore, due to hundreds of pre-built Docker images, it is easy to install any OS or app instantly. In addition, adjustments to a container operating system can be implemented without affecting other applications on the server – this also makes development easier. The container format also makes it easier for applications to move between servers, as they each have the right software environment.
Note: Before following the below steps you should have an Ec2 instance running on Amazon Cloud or Amazon Linux 2 on your virtual machine.
Docker Engine installation on AWS Ec2 Amazon Linux 2
1. Run system update
If you have just installed Amazon Linux 2 then it would be a really good idea to run the system update command. This will install the available updates including refreshing of system repository cache.
sudo yum update
2. Install Docker Engine on Amazon Linux 2 EC2
Next, unlike other Linux systems, we don’t need to add an official docker repository on AWS Ec2 Linux manually to get the latest version. It is already there, we just need to run a single command using the YUM packages manager to install Docker’s community edition.
sudo yum install docker
3. Start and enable Docker Service
Once the installation is done, start the Docker service and also check its status as well to ensure everything is running smoothly.
sudo service docker start sudo systemctl enable docker
Check status
sudo service docker status
4. Add your Ec2 user to the docker group
By default, we need to use Sudo with every docker command to install or run its images. However, this could be a little wired, hence if you don’t want it then add your current user to the Docker group.
sudo usermod -a -G docker ec2-user
or
If you have some other user then simply run the below command and it will automatically add your current user to the docker group.
sudo usermod -a -G docker $USER
5. Reboot your Amazon Ec2 Instance
After running the above commands, the docker is installed on your Amazon Linux successfully, now just reboot your instance to properly integrate your system user to the docker group.
sudo reboot
6. Test by pulling some Images to create a container
Now, let’s pull some docker images to create a container. This will also confirm that everything is working fine without any error.
Here we are pulling Ubuntu Image, you can download any other as per your choice to create your first container.
docker pull ubuntu
Once the pulling is completed, run your newly created Docker container
docker run -it container-name
Here the container name is Ubuntu, hence the command will be:
docker run -it ubutnu