DEV Community

Randika Madhushan Perera
Randika Madhushan Perera

Posted on

Docker Hands-On Part 01

01. Initializing the Docker Environment

Installing Docker CE

Installing Required Packages: If you are using Essential packages for Docker CE in CentOS, such as utils, device-mapper-persistent-data, and lvm2, are installed using the yum package manager.

I'm using the Linux EC2 2023 server.

To install Docker on Amazon Linux 2 or Amazon Linux 2023

1.Update the installed packages and package cache on your instance.

$ sudo yum update -y
Enter fullscreen mode Exit fullscreen mode

2.Install the most recent Docker Community Edition package.

For Amazon Linux 2, run the following:

$ sudo amazon-linux-extras install docker
Enter fullscreen mode Exit fullscreen mode

For Amazon Linux 2023, run the following:

$ sudo yum install -y docker
Enter fullscreen mode Exit fullscreen mode

3.Start and enable the Docker service

$ systemctl enable --now docker.service
$ systemctl ststus docker.service
Enter fullscreen mode Exit fullscreen mode

Add the ec2-user to the docker group so that you can run Docker commands without using sudo.

$ sudo usermod -a -G docker ec2-user
Enter fullscreen mode Exit fullscreen mode

Pick up the new docker group permissions by logging out and logging back in again. To do this, close your current SSH terminal window and reconnect to your instance in a new one. Your new SSH session should have the appropriate docker group permissions.

Verify that the ec2-user can run Docker commands without using sudo.

$ docker ps -a
Enter fullscreen mode Exit fullscreen mode

Top comments (0)