How to Install Docker on Amazon Linux 2023

Featured image for the srticle how to install Docker and docker compose on Amazon Linux 2023 Instance

How to Install Docker on Amazon Linux 2023 In a Step-by-Step Manner

Dear Reader, I hope you are doing well. In one of my previous posts, I explained how to install docker on Amazon Linux 2 EC2 instance. Today, I will talk about how you can install Docker on Amazon Linux 2023 or AL2023 Instance.

Apart from the installation of Docker on your Amazon Linux 2023 EC2 Instance, we’ll also set up Docker to run as a non-root user. Then we will start a simple hello world container to verify everything.

So, are you ready?

Let’s get started.

Don’t want to miss any posts from us? join us on our Facebook group, and follow us on Facebook, Twitter, LinkedIn, and Instagram. You can also subscribe to our newsletter below to not miss any updates from us.

An Overview of Amazon Linux 2023 and Docker

Amazon Linux 2023:

Amazon Linux 2023 or AL2023 is the newer generation of Linux AMI provided by Amazon Web Services. It is the successor of Amazon Linux 2.

  • It is more secure compared to Amazon Linux 2023
  • Provides Better Performance
  • Optimized with the latest innovations
  • Provides all the packages in the main repository

Read: Can You Install EPEL on Amazon Linux 2023?

Docker

Docker is an open-source tool that lets you build, run, test, and deploy applications easily across distributed systems.

  • Docker runs your application in a container.
  • Containers are portable and can run anywhere where docker is installed
  • Docker images are lightweight
  • There is a large community of people around Docker, so can get the required help.

Prerequisite:

You need to have an active AWS account running Amazon Linux 2023 instance. Here are two tutorials that can help you meet this prerequisite if not already met.

Steps to Install Docker on Amazon Linux 2023 Instance

  1. SSH into Amazon Linux 2023
  2. Search for Docker Package
  3. Install Docker on AL2023
  4. Check Docker Version
  5. Enable and Start Docker
  6. Verify Docker Running Status
  7. Run Hello World Container
  8. Allow Docker Commands to Run without Sudo(Optional)
  9. Install docker-compose on Amazon Linux 2023(Optional)
  10. Uninstall Docker (Optional)

Step 1: SSH into your Amazon Linux 2023

Before you can run commands on your Amazon Linux 2023 EC2 instance, you need to connect to it.

You can SSH into the instance from your local system using the below command –

ssh -i /path/my-key-pair.pem ec2-user@instance-public-ip

However, if you don’t want to use your local system, just select your instance and click Connect as shown in the screenshot below-

How to Install Docker on Amazon Linux 2023

Clicking on Connect will open a new window. Verify that ec2-user is shown in the user name field and click on Connect in the EC2 Instance Connect tab.

Within a matter of seconds, you will be inside your instance.

Step 2: Search for Docker Package

Let’s search for the Docker package available in Amazon Linux 2023 repository. You can also see the official Amazon Linux 2023 Packages page for all the available packages in Amazon Linux 2023 repository.

Or you can search in the terminal like below-

sudo dnf list | grep docker
How to Install Docker on Amazon Linux 2023 2

You can see the docker package in the above screenshot. docker.x86_64 is what we are interested in. Let’s proceed with the installation.

Step 3: Install Docker on AL2023

Before installing any software on your system it is highly recommended to run system update so that packages are updated to the latest versions.

We will roughly run the below 2 commands to update our Amazon Linux 2023 and install docker on it-

sudo dnf update //To Install Latest Update
sudo dnf install -y docker // Install Docker
How to Install Docker on Amazon Linux 2023 3

As soon as you type sudo dnf install -y docker command and hit enter, Docker is installed with all its dependencies on your Amazon Linux 2023 Instance.

Step 4: Check Docker Version

Although in the above screenshot, we are able to see the installed Docker version very clearly. Let’s check for the sake of completeness.

docker –version

Congratulations !! You have installed Docker on your Amazon Linux 2023 Instance. Let’s also do some of the required configurations.

Step 5: Enable and Start Docker

Docker is just installed but not yet running on your system. Type below two commands to start it and enable it.

sudo systemctl start docker.service // To start Docker Service
sudo systemctl enable docker // To Automatically start Docker on Reboot
How to Install Docker on Amazon Linux 2023 4

Step 6: Verify Docker Running Status

Now that we have started and enabled Docker, it should be in a running state. Let’s verify that using sudo systemctl status docker command-

sudo systemctl status docker
How to Install Docker on Amazon Linux 2023 5

As you can notice, docker is running on our Amazon Linux 2023 instance. We have come a long way.

Step 7: Run Hello World Container

We will use the very simple command docker run hello-world to run the official hello-world Docker image.

docker run hello-world
How to Install Docker on Amazon Linux 2023 6

Can you see the message – “This message shows that your installation appears to be working correctly.”

Wohooo !!!

But hey did you notice, we have used sudo with our docker run command? If you don’t use it, it errors out with the below error-

docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post “http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create”: dial unix /var/run/docker.sock: connect: permission denied.
See ‘docker run –help’.

If you don’t want to use sudo each time you run a docker command, allow docker to run without sudo in the next step.

Step 8: Allow Docker Commands to Run without Sudo(Optional)

You can use sudo usermod -a -G docker ec2-user command to add the user ec2-user to the docker group. Doing so allows the ec2-user user to run docker commands without using sudo.

After you add the user to a group, you need a logout/login for group membership to take effect. However, you can run newgrp docker command to make the changes take effect immediately.

sudo usermod -a -G docker ec2-user // Adds ec2-user to docker group 
newgrp docker // Make changes to group take affect immedeatly
How to Install Docker on Amazon Linux 2023 7

As you can notice, now we are able to run docker commands without any error.

Step 9: Install docker-compose on Amazon Linux 2023(Optional)

In case you need docker-compose as well, run the below set of commands to install it.

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose
How to Install Docker on Amazon Linux 2023 8

Step 10: Uninstall Docker (Optional)

In case you are installing Docker for learning purposes or you don’t need it anymore, you can uninstall it using the below command-

sudo dnf remove docker -y
How to Install Docker on Amazon Linux 2023 9

As you will notice, docker along with all its dependencies gets removed.

Conclusion

In this how-to guide, you learnt how to install Docker on Amazon Linux 2023 or AL2023 EC2 Instance

We roughly did-

  • Connected to our EC2 Instance
  • Searched Docker and Installed it.
  • Started Docker service and enabled it to start on reboot
  • Installed Docker Compose on It
  • Run a Simple Container

Were you able to Install Docker on Amazon Linux 2023 using this tutorial? Let me know in the comment section.

Enjoyed the content?

Subscribe to our newsletter below to get awesome AWS learning materials delivered straight to your inbox.

Don’t forget to motivate us-

Suggested Read:

Leave a Reply

Your email address will not be published. Required fields are marked *