This page explains how to install Docker on a fresh Ubuntu 22.04. Docker is a containerization technology. Docker provides a way to run applications securely isolated in a container, packaged with all its dependencies and libraries. This makes it easier to deploy and run applications, as everything required to run the application is included in the container. With docker can run any version of Linux distributions, application and services like web servers, database management systems, programming languages...
The following has been tested with these versions:
Before installing Docker, start by updating your system with the following command:
sudo apt update -y && sudo apt upgrade -y
Don't use apt install docker
since the version in the repos in not necessary the last one.
To remove a any older version of Docker before attempting to install the last version, run the following command :
sudo apt-get remove docker docker.io containerd runc
The output should look like:
Package 'docker' is not installed, so not removed
Package 'docker.io' is not installed, so not removed
Package 'containerd' is not installed, so not removed
Package 'runc' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Before installing Docker, we have to Install the Docker repository. Let's start by installing the following packages:
sudo apt-get install ca-certificates curl gnupg lsb-release
Create a folder for downloading the Docker's official GPG key:
sudo mkdir -p /etc/apt/keyrings
Download the key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Finally set up the repository with the following command:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update the apt
package index:
sudo apt update
You should see the following lines as output of the last command. It confirms the Docker repository has been properly added.
Get:3 https://download.docker.com/linux/ubuntu jammy InRelease [48,9 kB]
Get:6 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [11,1 kB]
Now that the repository is added, just install docker with the following command:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Check that docker is working properly by running the hello-world
image:
sudo docker run hello-world
This commands downloads the image and runs it in the container. The container prints a confirmation message and exits:
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:c77be1d3a47d0caf71a82dd893ee61ce01f32fc758031a6ec4cf1389248bb833
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
Docker is installed and works properly.
You can also check the version installed with docker -v
:
$ docker -v
Docker version 20.10.22, build 3a2c30b
You probably noticed that the test image hello-world
has been started with root privileges.
The Docker daemon always runs as the root user.
To run docker
as non-root user, create a group named docker
:
sudo groupadd docker
Add the current user to the docker
group:
sudo usermod -aG docker $USER
Reboot your machine to activate changes. In some case, log out and log back could do the job.
Check that docker can be run without root privileges:
docker run hello-world
That's all folks!