Docker Series (Chapter 0/4): Installing docker-engine in Ubuntu
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
andiptables-legacy
. Firewall rules created withnft
are not supported on a system with Docker installed. Make sure that any firewall rulesets you use are created withiptables
orip6tables
, and that you add them to theDOCKER-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 | # Add Docker's official GPG key: |
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 | sudo systemctl enable docker.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 | shy@flash-shy:~$ sudo docker run hello-world |
And then, you could find the image called hello-world
in the image list.
1 | shy@flash-shy:~$ sudo docker images |
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 | shy@flash-shy:~$ docker images |
Congratulations to you! Up to now, you installed docker-engine successfully!