Docker is an open-source platform that allows you to develop, build, deploy, test, manage and run applications in containers. Containers are standardized units that include libraries, system tools, code, and runtime to run software or application.
Comparing Docker containers and Virtual Machines, here you can run multiple workloads (containers) on a single OS. Docker containers share the host OS kernel. Where, virtual machine does not provide the operating system kernel, it has its own. And the VMs are much more resource-intensive, instated of containers that are lightweight and don’t need separate operating systems. The differences between these two kind of infrastructures are much more.
One of the big advantages of Docker is ease of installation on most of the popular Linux distros and Windows.
In this article, I will show you how to install Docker Engine on Ubuntu 22.04.
Installation on other Linux distributions can be different. Look at official documentation
1. Docker Engine installation
At below, you can find info about a current operating system – Ubuntu 22.04.5 LTS
1. At first, let’s confirm that any old version of Docker isn’t installed on the system.
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
2. Next, 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
3. 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
4. Install the latest Docker packages.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
5. Verify, that Docker Engine is working properly and pull hello-world image from the Docker Hub
sudo docker run hello-world
6. To automatically start Docker and containerd on boot, run commands from the below.
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
2. Set up non-root user to manage Docker
If you want to avoid typing sudo every time as a non-root user running Docker, you need to create a docker group and add user(s) to it.
1. Create the docker group and a current user to this group:
sudo groupadd docker
sudo usermod -aG docker $USER
2. Log out (or restart machine) and log in again to apply changes. Check, if you can pull images without sudo.
newgrp docker
docker run hello-world
3. To list information about a version of the running Docker Engine type a command:
docker version