In this post I want to show you how to install Docker Engine on Ubuntu and run your first container. The installation steps will work on the following Ubuntu versions:
- Ubuntu Oracular 24.10
- Ubuntu Noble 24.04
- Ubuntu Jammy 22.04
- Ubuntu Focal 20.04
Table of Contents

Uninstall old versions
In my lab, I will use Ubuntu 24.04. As suggested in the Docker documentation, the first step is to uninstall any conflicting software that may affect the current installation.
Run a similar command on your machine. It is a for loop that uninstalls sequantially the packges mentioned in the list.
petru@ubuntu2404:~$ for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

As you can see in the below screenshot, there isn’t any package installed on my machine.

Install Docker Engine using the apt repository
There are multiple installation methods for installing Docker Engine. I will install it using the apt repository.
Add Docker’s official GPG key
Before installing Docker, you need to add the Docker official GPG key to your machine.
petru@ubuntu2404:~$ sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

The above commands install ca-certificates and curl on your machine. They also download the GPG key from Docker and put it in the file /etc/apt/keyrings/docker.asc.
petru@ubuntu2404:~$ sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease
Get:2 http://archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Hit:3 http://archive.ubuntu.com/ubuntu noble-backports InRelease
Hit:4 https://aquasecurity.github.io/trivy-repo/deb generic InRelease
Hit:5 http://security.ubuntu.com/ubuntu noble-security InRelease
Hit:6 https://debian.datastax.com/enterprise stable InRelease
Fetched 126 kB in 1s (93.7 kB/s)
Reading package lists... Done
W: https://debian.datastax.com/enterprise/dists/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
ca-certificates is already the newest version (20240203).
ca-certificates set to manually installed.
curl is already the newest version (8.5.0-2ubuntu10.6).
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
petru@ubuntu2404:~$ ls /etc/apt/keyrings/docker.asc
/etc/apt/keyrings/docker.asc
petru@ubuntu2404:~$ cat /etc/apt/keyrings/docker.asc
-----BEGIN PGP PUBLIC KEY BLOCK-----

Add the Docker repository to the Apt sources
Next, you need to add the Docker repository to the Apt sources. You need to run a similar command.
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

As you can see in the above image, the file docker.list was not present on my machine.
Download the latest package information from all configured sources
After adding the Docker repository, you need to download the latest package information from all configured sources.
petru@ubuntu2404:~$ sudo apt-get update
Hit:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu noble InRelease
Hit:3 http://archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu noble-backports InRelease
Get:5 https://download.docker.com/linux/ubuntu noble InRelease [48.8 kB]
Hit:6 https://aquasecurity.github.io/trivy-repo/deb generic InRelease
Hit:7 https://debian.datastax.com/enterprise stable InRelease
Get:8 https://download.docker.com/linux/ubuntu noble/stable amd64 Packages [18.9 kB]
Fetched 67.7 kB in 2s (43.5 kB/s)
Reading package lists... Done
W: https://debian.datastax.com/enterprise/dists/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
petru@ubuntu2404:~$

Install Docker packages
The last step is to install the Docker packages. Run a similar command on your machine.
petru@ubuntu2404:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
docker-ce-rootless-extras git git-man liberror-perl libslirp0 pigz slirp4netns
Suggested packages:
aufs-tools cgroupfs-mount | cgroup-lite git-daemon-run | git-daemon-sysvinit git-doc git-email git-gui gitk gitweb
git-cvs git-mediawiki git-svn
The following NEW packages will be installed:
containerd.io docker-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin git
git-man liberror-perl libslirp0 pigz slirp4netns
0 upgraded, 12 newly installed, 0 to remove and 8 not upgraded.
Need to get 132 MB of archives.
After this operation, 482 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Confirm that Docker is up and running
After the installation is complete, confirm that Docker is up and running.
petru@ubuntu2404:~$ systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)
Active: active (running) since Sun 2025-02-09 10:56:53 GMT; 1min 25s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 23240 (dockerd)
Tasks: 14
Memory: 22.9M (peak: 24.5M)
CPU: 1.025s
CGroup: /system.slice/docker.service
└─23240 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Feb 09 10:56:51 ubuntu2404 systemd[1]: Starting docker.service - Docker Application Container Engine...
Feb 09 10:56:52 ubuntu2404 dockerd[23240]: time="2025-02-09T10:56:52.006781448Z" level=info msg="Starting up"
Feb 09 10:56:52 ubuntu2404 dockerd[23240]: time="2025-02-09T10:56:52.008807066Z" level=info msg="OTEL tracing is not >
Feb 09 10:56:52 ubuntu2404 dockerd[23240]: time="2025-02-09T10:56:52.009167264Z" level=info msg="detected 127.0.0.53 >
Feb 09 10:56:52 ubuntu2404 dockerd[23240]: time="2025-02-09T10:56:52.223079284Z" level=info msg="Loading containers: >
Feb 09 10:56:53 ubuntu2404 dockerd[23240]: time="2025-02-09T10:56:53.094788486Z" level=info msg="Loading containers: >
Feb 09 10:56:53 ubuntu2404 dockerd[23240]: time="2025-02-09T10:56:53.142048847Z" level=info msg="Docker daemon" commi>
Feb 09 10:56:53 ubuntu2404 dockerd[23240]: time="2025-02-09T10:56:53.142443648Z" level=info msg="Daemon has completed>
Feb 09 10:56:53 ubuntu2404 dockerd[23240]: time="2025-02-09T10:56:53.284697626Z" level=info msg="API listen on /run/d>
Feb 09 10:56:53 ubuntu2404 systemd[1]: Started docker.service - Docker Application Container Engine.
petru@ubuntu2404:~$

Run docker commands without sudo
By default, you will need to run docker commands with sudo. Docker creates a group on your machine, named docker. To be able to run docker commands without using sudo, you will need to add your user acount to the docker group. Please follow the below steps in order to run docker without sudo. The usermod command adds your user account to the docker group.
petru@ubuntu2404:~$ docker ps
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.47/containers/json": dial unix /var/run/docker.sock: connect: permission denied
petru@ubuntu2404:~$ grep docker /etc/group
docker:x:984:petru
petru@ubuntu2404:~$ sudo usermod -aG docker petru
petru@ubuntu2404:~$ exit

Run your first container using Docker Engine
The final step is to run your first container. Please run a similar command on your machine. I will use the hello-world image for my first container. In the ouput of the command, you can see what docker is doing in the background.
petru@ubuntu2404:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:d715f14f9eca81473d9112df50457893aa4d099adeb4729f679006bf5ea12407
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:
https://docs.docker.com/get-started/

Great job. You have installed Docker Engine on your machine and ran your first container.
