What is Docker?

The name Docker is derived from the term used in maritime shipping, referring to dockworkers. It serves as a metaphorical representation.

In traditional shipping, goods are packed into standardized containers, enabling seamless transfer across different modes of transportation, such as trucks, trains, and ships. Similarly, Docker provides a standardized container that packages applications and all their dependencies together, allowing them to run efficiently and reliably across different environments, such as development, testing, and production. Docker is just one of the most commmon technical tools in the area of containerization. What’s more, such as: Podman, CRI-O, Containerd are also useful containerization tools.

Containerization leverages Linux container technologies such as LXC and cgroups to provide a lightweight method for running applications in isolation. Container looks like a box including all dependencies files or applications, developers only need to develop in this environment. After developing, they could delivery programs/projects to operation teams by image directly. This method avoid the confliction between development & production environment due to configuration differences or dependency conflicts.

Prerequisites

Firewall

Docker is only compatible with iptables-nft and iptables-legacy. Firewall rules created with nft are not supported on a system with Docker installed. Make sure that any firewall rulesets you use are created with iptables or ip6tables, and that you add them to the DOCKER-USER chain.

Operating system

  • Ubuntu Oracular 24.10

  • Ubuntu Noble 24.04 (LTS)

  • Ubuntu Jammy 22.04 (LTS)

  • Ubuntu Focal 20.04 (LTS)

Docker Engine for Ubuntu is compatible with x86_64 (or amd64), armhf, arm64, s390x, and ppc64le (ppc64el) architectures.

Installing docker-engine

I followed the Docker official website for the installation.

Uninstalling the old version

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

Installing by using apt repository

There are many various methods to install docker-engine, I will use the recommended method to install here.

Setting up Docker’s apt repository

1
2
3
4
5
6
7
8
9
10
11
12
13
# Add Docker's official GPG key:
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

# Add the repository to Apt sources:
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
sudo apt-get update

Installing the latest version

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

Setting auto-start automatically at boot and take effect immediately

1
2
sudo systemctl enable docker.service
sudo systemctl enable containerd.service

Confirming the installation result

1
sudo docker run hello-world

If you install the docker-engine successfully, there is a sentence to inform and congratulate to you.

1
2
3
4
5
6
7
8
9
10
shy@flash-shy:~$ sudo 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.
......

And then, you could find the image called hello-world in the image list.

1
2
3
4
shy@flash-shy:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 74cc54e27dc4 32 hours ago 10.1kB
......

Granting regular users access to the docker-engine

You must receive errors when trying to run without root. The reason is that the docker user group exists but contains no users, which is why you’re required to use sudo to run Docker commands.

The Docker daemon binds to a Unix socket, not a TCP port. By default it’s the root user that owns the Unix socket, and other users can only access it using sudo. The Docker daemon always runs as the root user.

Creating the docker group and add your user

Sometimes, you could skip this step because the docker group has already been created.

1
sudo groupadd docker

Adding your user to the docker group

1
sudo usermod -aG docker $USER

Restarting

1
reboot

Confirming without root privilege

1
2
3
4
shy@flash-shy:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 74cc54e27dc4 32 hours ago 10.1kB
......

Congratulations to you! Up to now, you installed docker-engine successfully!