Newsletter Subscribe
Enter your email address below and subscribe to our newsletter
Want to install Docker in Ubuntu 24.04 LTS? Well, if you ok with having a slightly older (but rock-stable) version of Docker, then it can be installed using the following command:
sudo apt install docker.io docker-compose
But hey, you might want the latest version of Docker or some basic configuration like running Docker without sudo so I wrote a detailed guide covering the following:
Let’s start with the first one.
Table of Contents
Sounds funny? It is not. Docker being one of the most popular containerization tools, is available in the default repository of Ubuntu and can be installed by executing one command.
There’s only one con of this method and that is you don’t get the most recent version of Docker but on the bright side, it is well tested and stable.
To install Docker using the default repository, use the following command:
sudo apt update && sudo apt install docker.io docker-compose
Once done, you can check the installed version using the following command:
docker --version
As you can see, while writing, it gave me Docker version 24.0.7.
To install the latest version of Docker on Ubuntu 24.04 LTS, I will be using the official repository of Docker. But before that, it is important to remove the previous installation of Docker and to do so, you can use the following command:
sudo apt remove docker-* --auto-remove
Once you are done removing the old installation of Docker, install the necessary dependencies using the given command:
sudo apt install ca-certificates curl gnupg lsb-release
Next, you need to create a new directory with specific permissions to store cryptographic keyrings which will be used by the apt package manager:
sudo install -m 0755 -d /etc/apt/keyrings
Now, download the GPG keys for Docker which will be used to validate packages while installation:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Once you are done adding GPG keys to the system, change the permission of the GPG keys so that every user present on the system can read them:
sudo chmod a+r /etc/apt/keyrings/docker.gpg
Now, add the Docker repository to your system:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Finally, update the repository index to take effect from the changes you have made to the system:
sudo apt update
It is time to install the latest Docker on Ubuntu 24.04 LTS on your system using the following command:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Now, you can check the installed version of Docker:
docker -v
As you can see, it is 3 iterations ahead (Docker version 27.2.1) of what the default repository (Docker version 24.0.7) gave me.
In this section, I will show you how you can install a Docker image on Ubuntu. For that purpose, I will be using a test image called Hello World.
To install the Hello World Docker image on Ubuntu, all you have to do is execute the following command:
sudo docker run hello-world
As you have not installed the image, it won’t be able to find the image from the local system and fetch it from the Docker marketplace and then run it for you:
Some users might come across the following error “Cannot connect to the Docker daemon”. Don’t worry, all you have to do is reboot your system and the problem will be solved:
Note: This method only works with a user who already has a super user privilege. So think of it as a convenience feature.
So far, everything is going well until you notice a weird quirk of using Docker and that is you can not use the docker command without sudo.
Personally, I don’t like using sudo every time I have to interact with Docker so I follow the given steps every time I make a fresh install.
So in this section, I will walk you through how you can use the docker command without sudo on Ubuntu 24.04 LTS.
The first step is to create a group named Docker
:
sudo groupadd docker
Now, add the user to the recently created Docker
group:
sudo usermod -aG docker <username>
Note: Make sure to only add a user who already has superuser privileges.
If you are using VM, then you have to reboot your system to take effect from the changes you have just made to run Docker without sudo.
From now on, you will be able to run the docker command without sudo. For example, here, I have executed the Docker Hello World image without sudo:
There you have it!
This was my take on how you can install Docker on Ubuntu 24.04 LTS using multiple methods including installing Docker in one shot and installing the latest version of Docker on Ubuntu.
I have also mentioned how you can run the Hello World test image to check if the installation is working correctly or not and at the end, shared a bonus tip on how you can use the docker command without sudo.
I hope you will find this guide helpful.