Skip to content
Home ยป How to Install Docker on the Linux Server?

How to Install Docker on the Linux Server?

A Docker is a platform for developing, shipping, and running container applications. Docker is like installing a virtual machine application on your laptop or server, whether itโ€™s VirtualBox, VMWare, or Xen, so you can test various operating systems or applications on it without putting your laptop or server in danger.

 

Problem

How to install Docker on the Linux server?

 

Solution

A. Docker summary

The key differentiator between containers and virtual machines is that virtual machines virtualize an entire machine down to the hardware layers, and containers only virtualize software layers above the operating system level. Take a look at the image below to make the difference between virtual machines and Docker clearer:

Comparison of Docker and Virtual Machine Architecture (image credit from atlassian.com)

 

The table below shows the comparison between virtual machines and Docker:

Comparison between Docker and virtual machine (Image credit from huawei.com)

 

Below is a brief explanation of the terms in Docker:

  • ๐——๐—ผ๐—ฐ๐—ธ๐—ฒ๐—ฟ ๐—ฃ๐˜‚๐—น๐—น: Downloads images from Docker Hub if not locally available
  • ๐——๐—ผ๐—ฐ๐—ธ๐—ฒ๐—ฟ ๐—•๐˜‚๐—ถ๐—น๐—ฑ: Creates a local image using a Dockerfile, enabling custom images
  • ๐——๐—ผ๐—ฐ๐—ธ๐—ฒ๐—ฟ ๐—ฃ๐˜‚๐˜€๐—ต:Uploads images to Docker Hub, allowing sharing
  • ๐——๐—ผ๐—ฐ๐—ธ๐—ฒ๐—ฟ ๐—ฅ๐˜‚๐—ป: Takes an image to run a container, useful for starting web servers or other applications
  • ๐——๐—ผ๐—ฐ๐—ธ๐—ฒ๐—ฟ ๐—œ๐—บ๐—ฎ๐—ด๐—ฒ: Read-only templates forming the base of containers, including all application dependencies
  • ๐——๐—ผ๐—ฐ๐—ธ๐—ฒ๐—ฟ ๐—–๐—น๐—ถ๐—ฒ๐—ป๐˜: Interacts with Docker, sending instructions to the Docker daemon to execute tasks
  • ๐——๐—ผ๐—ฐ๐—ธ๐—ฒ๐—ฟ Daemon: Handles all requests, including building, running, and distributing containers
  • ๐——๐—ผ๐—ฐ๐—ธ๐—ฒ๐—ฟ ๐—–๐—ผ๐—ป๐˜๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฟ๐˜€: Include everything needed to run an application, such as code, libraries, and configurations
  • ๐——๐—ผ๐—ฐ๐—ธ๐—ฒ๐—ฟ ๐—ฅ๐—ฒ๐—ด๐—ถ๐˜€๐˜๐—ฟ๐˜†: Stores Docker images, with Docker Hub as a public registry and the option to create private ones

The image below is a picture of how the Docker works:

How Docker works (Image credit from geeksforgeeks.org)

 

B. Install Docker

In general, use the command belowย  to install Docker on Linux:

curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

 

But after you execute the commands above, there is an error like this when you install it in RockyLinux:

ERROR: Unsupported distribution ‘rocky’

You have to install Docker manually using these commands:

sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

 

Or when you install Docker in OpenSUSE, you get an error like this:

ERROR: Unsupported distribution ‘opensuse-leap’

Use the commands below to install Docker in OpenSUSE:

sudo zypper install -y docker docker-compose docker-compose-switch

 

 

C. After installing Docker

Use the following command to run Docker:

sudo systemctl restart docker
sudo systemctl enable docker

 

To see the version of Docker you installed, use the command below:

docker info
Running the docker info command

 

D. Test the application in Docker

After that, to see whether Docker is running well on the server, use the command below to run the hello-world container on your server:

docker run hello-world

 

If you have got the error like the image below:

Error when running the docker run command

 

ERROR: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get “http://%2Fvar%2Frun%2Fdocker.sock/v1.47/info”: dial unix /var/run/docker.sock: connect: permission denied

Then you have to run the below command:

sudo usermod -aG docker $USER

 

Log out of your server and log in again. After that, you should be able to run the Docker commands like in the image below:

Test the Docker run command

 

That way, your Docker application is ready to use.

 

Note

You donโ€™t have to use Docker to create and run containers, but you can use other applications such as podman, buildah, cri-o, etc. However, Docker is the most popular at the moment. Also, the terms and workings of various container applications are almost the same, so if you understand the terms and workings of Docker, then you will also understand the terms and workings of other container applications. To learn about basic commands in Docker, go to this page.

 

References

 

image_pdfimage_print
Visited 30 times, 1 visit(s) today
Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *