What is Docker?
Docker is an application that simplifies the process of managing application processes in containers. Containers let you run your applications in resource-isolated processes. They’re similar to virtual machines, but containers are more portable, more resource-friendly, and more dependent on the host operating system.
Step 1 - Installing Docker
Prerequisites
To follow this tutorial, you will need the following:
- One Ubuntu 22.04 server/VM, including a
sudo
non-root user and a firewall.
First, update your existing list of packages
sudo apt update -y
install a few prerequisite packages which let apt
use packages over HTTPS
sudo apt install apt-transport-https ca-certificates curl software-properties-common
add the GPG key for the official Docker repository to your system
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Add the Docker repository to APT sources
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Do a sudo apt update -y
to update your existing list of packages again for the addition to be recognized.
Make sure you are about to install from the Docker repo instead of the default Ubuntu repo
apt-cache policy docker-ce
You’ll see output like this, although the version number for Docker may be different
docker-ce:
Installed: (none)
Candidate: 5:20.10.14~3-0~ubuntu-jammy
Version table:
5:20.10.14~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:20.10.13~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
Now lets install Docker
sudo apt install docker-ce
Check the status
sudo systemctl status docker
Step 2 — Executing the Docker Command Without sudo
(Optional)
By default, the docker
command can only be run the root user or by a user in the docker group, which is automatically created during Docker’s installation process. If you attempt to run the docker command without prefixing it with sudo
or without being in the docker group, you’ll get an output like this
Output
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?. See 'docker run --help'.
If you want to avoid typing sudo
whenever you run the docker command, add your username to the docker group
sudo usermod -aG docker ${USER}
To apply the new group membership, log out of the server and back in. Confirm that your user is now added to the docker group by typing
id ${USER}
You should see docker
in groups. Now you can use docker
command without sudo