Docker installation on Ubuntu 24.04 can be done by adding its official repository; however, there is another easy way, i.e., using the SNAP.
Snap is a popular universal package manager that works on almost all Linux distros. It can be used to install Docker using a single command. Docker is a platform for developing, shipping, and running applications inside lightweight, portable containers. It has already been used globally by hundreds of enterprises and developers.
This tutorial teaches installing Docker CE on your Ubuntu 24.04 LTS system using SNAP.
Step 1: Refresh your system
Refresh the package repository of Ubuntu 24.04 and install the security updates using the given command.
sudo apt update
Step 2: Install Docker via SNAPon Ubuntu 24.04
Ubuntu 24.04, like its previous versions, comes by default with SNAP out of the box. Hence, we just need to run the given command to install the Docker in an isolated environment.
sudo snap install docker
Step 3: Create a Docker System Group
Installing Docker using SNAP will not automatically create a Docker group, so we need to do that manually. We need to create a Docker group with the appropriate permissions to use the Docker commands without sudo.
The below syntax uses the “–system” option to specify that the group being created is a system group. System groups typically have a lower GID (Group ID) and are used for system-related tasks and daemons. Hence, they usually have unique permissions and are not meant for regular user accounts.
sudo addgroup --system docker
Step 4: User Docker without sudo
Once we have created the group, we can add our current user to it so that we can run the docker commands without using “sudo” every time.
sudo adduser $USER docker
newgrp docker
Sometimes, even after running the newgrp command, the terminal doesn’t immediately recognize the user added to the group. In such a case, log out and log in again.
Step 5: Disable and Enable Snap Docker
You must also disable and enable Snap’s Docker service to apply your changes.
sudo snap disable docker
sudo snap enable docker
Step 5: Create your first Container
Now, we can use the Docker command to create the required containers; here is an example if you are new to it.
In this example, we download the Ubuntu docker image and create a container using it.
docker pull ubuntu
Create container:
docker create -it --name test ubuntu
Start container
docker start test
Get the command line of the installed container:
docker attach test
Uninstallation
In case you think Docker installed using Snap is creating some problems and want to remove it, then here is the command to follow:
sudo snap remove docker
Other Articles: