A Docker app makes it easy to run/process manage sites/applications in isolated areas/containers.
In containers, it is possible to run applications with resources isolated from the common system. Docker is very similar to a virtual machine like VirtualBox, but much more portable and resource efficient.
OS packages need to be updated before installing Docker.
apt update
Install the required packages and add a new repository:
apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
Update the packages with the new repository:
apt update
Now let's install Docker itself.
apt-get install docker-ce docker-ce-cli containerd.io
Check the Docker version:
docker --version
Let's check the status of Docker:
systemctl status docker
If it does not start, then run:
systemctl start docker
And add to autorun.
systemctl enable docker
In order to test in real conditions whether it is possible to access from Docker Hub and download a test container, run the following command:
docker run hello world
If Docker is working properly, you should be able to observe this output:
The docker command is only run as root by default, or as a user in the docker group (the group is created automatically when docker is installed).
Therefore, if you run the docker command without superuser (root) rights, you will get an error.
In order not to use the sudo prefix each time, let's add the username from which we "sit" the docker group.
sudo usermod -aG docker ${USER}
Apply the added rule without restarting the server:
su - ${USER}
Enter the password on behalf of the user in which you work.
Check if your user is added to the docker group:
id -nG
Now we can enter the docker command without root privileges.
To view all active/running containers, use the following command line:
docker ps
As you can see, no container is running. But we just downloaded and ran the hello-word test container! This container is no longer running, but still present in our system.
To see it, use the following command line:
docker ps -a
As you can see, our hello-word container is loaded but not started.
And so, in this article, we looked at how easy it is to install Docker and run a test container.
You can learn how to install the services you need in Docker containers from the following articles.