July 2, 2024
Tutorials

How to Install Docker on Ubuntu 24.04

install docker on ubuntu 24.04

Docker is one of the powerful platforms that facilitate developers in automating the deployment of their applications in lightweight and portable containers. In addition to building and deployment, it also enhances your development workflow.

Furthermore, Docker simplifies the process of building, sharing, and running applications with efficiency.

This educational guide will cover the steps necessary to install Docker on the Ubuntu 24.04 system. Read this article if you are using an older version of Ubuntu 22.04.

How to Install Docker on Ubuntu 24.04?

The following few steps will be performed for installing the Docker package on your Ubuntu 24.04 system.

Step 1: Update and Refresh Ubuntu Repository

To prepare your Ubuntu machine for new installation, run the below update command:

sudo apt update

This command is essential for preparing your system for new packages and resolving compatibility issues.

Step 2: Remove Existing Docker Packages

To prevent or avoid any conflict, utilize the given-blow command to remove any existing packages related to Docker:

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
 

When the above-mentioned command executes, it will remove all the old Docker files that potentially cause errors.

Step 3: Install Necessary Packages

The packages, such as ca-certificates, curl necessary for Docker installation. Therefore, you are required to install these packages on your Ubuntu 24.04 system:

sudo apt install ca-certificates curl -y

According to the output message, these two packages already exist.

Step 4: Create a Keyring Directory for Docker

Upon completing the above steps, let’s create a keyring directory for docker on your Ubuntu 24.04 machine:

sudo install -m 0755 -d /etc/apt/keyrings

This command will ensure the keyrings directory has the proper permissions after creation.

Step 5: Download Docker’s GPG Key

Next, execute the command to download Docker’s official GPG key and save it to a specified location (i.e. /etc/apt/keyrings) on your system:

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

The command has downloaded Docker’s official GPG key to “/etc/apt/keyrings” on your system.

Step 6: Permit All Users

To ensure that the Docker GPG key file is readable by all users on your Ubuntu system, run the command:

sudo chmod a+r /etc/apt/keyrings/docker.asc

With this command, you permitted all users to read the Docker GPG key file.

Step 7: Add Docker’s APT Repository to Your System

Through the following command, you can add Docker’s APT repository to the system’s package sources list (i.e. /etc/apt/sources.list.d/docker.list):

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ 
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ 
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

The command provided above enables the system to fetch Docker’s packages using the APT package manager.

Step 8: Refresh Your Ubuntu Files

After installing the necessary packages, you can now refresh your Ubuntu 24.04 package files via the command:

sudo apt update

Once your system has refreshed, you will see a new line containing the Docker package on your screen.

Step 9: Install Docker and Associated Files

After successfully preparing your system, execute the following command to install Docker and its associated packages on your Ubuntu 24.04 system:

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
 

As illustrated above, your system has been set up with all the necessary packages related to Docker.

Step 10: Verify Docker’s Installation

If you are curious about the installed version of the Docker, then run the command to check the version number:

docker --version

The Docker version (i.e. 26.1.3) will be shown on your terminal screen when the command executes.

Step 11: Test Docker’s Image

Finally, you can confirm the Docker installation by testing a Docker image. For instance, run the command to check if the Docker is working correctly:

sudo docker run hello-world
 

If you see a greeting message, such as “Hello from Docker!”, it shows that you have successfully configured Docker on your Ubuntu 24.04 system.

Conclusion

Ubuntu 24.04 allows for the installation of Docker with a few lines of commands. After preparing your system, such as installing updates and adding Docker’s repository, use the command “sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y” to install Docker.

To further confirm your installation, you can run the “sudo docker run hello-world”.

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video