Docker – Installing on Linux


How to Install Docker on Linux?



”;


Docker has transformed the software development industry completely by allowing programmers to bundle their apps and all of their dependencies into small, lightweight units known as containers. By separating apps from the underlying operating system, these containers provide reliable performance and easy deployment in a variety of environments.

If you”re a Linux user hoping to take advantage of containerization, this chapter is the perfect place to be. You will be able to install Docker on your Linux system using various ways that will be explained in this detailed guide. We will provide detailed instructions according to your requirements, regardless of whether you like to use pre-built packages, download DEB files, or make use of handy installation scripts.

We will discuss in detail, the following approaches to installing Docker on Linux −

  • Install using the apt repository
  • Install from a package
  • Install using the convenience script

So, let’s understand these approaches to install Docker on Ubuntu.

Prerequisites to Install Docker on Linux

Make sure your Linux system satisfies the prerequisites before starting the Docker installation process. This will ensure that the Docker installation is done smoothly and in the best way.

Use a 64-bit Architecture − Docker works best in a 64-bit setting. You can use the “uname -m” command in your terminal to confirm the architecture of your system. It will be difficult to install Docker directly if your system is 32-bit. However, alternative solutions are available on the internet for particular use cases.


Docker Installation 1

Use Kernel Version 3.10 or Higher − A stable Linux kernel is required for Docker to work as expected and in the best way. You can verify that the kernel version you”re using is 3.10 or higher.

You can do so using the “uname -r” command in your terminal. This will give you the version of your kernel. You may check the documentation for your distribution to determine the best course of action if you need an update.


Docker Installation 2

Package Management − The approach to installing Docker largely depends on the package manager for your Linux distribution. APT (Ubuntu/Debian) and Yum (Red Hat/CentOS) are two popular examples.

It’s always good to follow the installation guidelines unique to your distribution if you are familiar with these distributions. In this chapter, we will discuss the approaches for Ubuntu. Similar commands can be used for other Linux distributions depending on their package managers.

Additional Considerations

Virtualization Support − You should ensure that your system is compatible with the hardware virtualization technologies such as KVM for better performance. This is especially important when executing specific containerized apps.

Sudo Access − Almost all the installation techniques require sudo access, so make sure you have that handy.

Once you meet these requirements, you are in a good position to install Docker in the best possible way on your Linux machine. In the following section, we”ll explore the different installation techniques, so stay tuned!

Installing Docker using APT Repository

Before installing a Docker Engine on a new host for the first time, it’s important to set up the Docker repository. After that, you can easily install or update Docker from that repository. To set up the Docker’s apt repository, you can use the below set of commands.


$ sudo apt-get update


Docker Installation 3


$ sudo apt-get install ca-certificates curl


Docker Installation 4


$ 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


Docker Installation 5

The next step is to 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


Docker Installation 6

Note − If you are using another derivative of Ubuntu such as Linux Mint or others, you may need to replace VERSION_CODENAME with UBUNTU_CODENAME in the above command.

The next step is to install the Docker packages. To install the latest version, you can run the below commands −


$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin


Docker Installation 7

After you have completed the installation, you can verify the installation is successful by running the hello-world image.


$ sudo docker run hello-world


Docker Installation 8

The above command downloads the hello-world image from the Docker repository and runs a container associated with it. It prints a message and exits. This verifies the successful installation of the Docker engine on your Ubuntu host.

Instead of installing the latest version, you can also install a specific version of the Docker engine using the below set of commands. The first command lists the available Docker versions for Ubuntu.


# List the available versions:
apt-cache madison docker-ce | awk ''{ print $3 }''


Docker Installation 9

Then you can set the desired version in a variable and install it using the below commands.


$ VERSION_STRING=5:26.1.1-1~ubuntu.22.04~jammy
$ sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING 
   containerd.io docker-buildx-plugin docker-compose-plugin

Installing Docker From a Package

Instead of installing Docker from the APT repository, you can also manually download the deb files for the specific release versions and install them. But in this case, if you want to upgrade the Docker engine versions, you will have to do it manually.

  • Visit https://download.docker.com/linux/ubuntu/dists/.
  • Then, select the version of Ubuntu from this list.
  • Then, go to the path – pool/stable and select the architecture of your Linux host (amd64, armhf, arm64, or s390x).
  • After that, you need to download the following deb files.

    • containerd.io_<version>_<arch>.deb
    • docker-ce_<version>_<arch>.deb
    • docker-ce-cli_<version>_<arch>.deb
    • docker-buildx-plugin_<version>_<arch>.deb
    • docker-compose-plugin_<version>_<arch>.deb
  • After downloading these, you can install these packages using the following command. This will also start the Docker daemon automatically.


$ sudo dpkg -i ./containerd.io_<version>_<arch>.deb 
   ./docker-ce_<version>_<arch>.deb 
   ./docker-ce-cli_<version>_<arch>.deb 
   ./docker-buildx-plugin_<version>_<arch>.deb 
   ./docker-compose-plugin_<version>_<arch>.deb

$ sudo service docker start

Installing Docker using Convenience Scripts

You can also install Docker using a convenience script provided by Docker at https://get.docker.com/. This is useful for development environments however not recommended for production. But it is useful in creating a provisioning script customized for production environments also.

These are the things that the script does along with its limitations.

  • To run, the script needs root or sudo capabilities.
  • The script makes an effort to identify your Linux version and distribution and sets up your package manager for you.
  • You cannot change most installation parameters with the script.
  • Without requesting approval, the software installs suggestions and prerequisites. This could install a lot of packages, depending on how your host machine is configured right now.
  • The script installs runc, containerd, and Docker at the most recent stable release by default. Docker versions may unexpectedly upgrade significantly if this script is used to provision a machine. Upgrades should always be tested in a test environment before being deployed to live systems.
  • It is not intended for the script to upgrade an already-existing Docker installation. Dependencies might not be updated to the anticipated version when using the script to update an already-existing installation, leading to versions that are out of date.


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

On Debian-based distributions, the Docker engines start automatically. On RPM-based distributions, you can use systemctl or service commands to start it manually.

How to Uninstall Docker Engine on Linux?

Uninstalling the Docker engine on Ubuntu is simple. You can use the below commands to uninstall the Docker packages and then remove all the configurations and images, containers, etc.


$ sudo apt-get purge docker-ce docker-ce-cli containerd.io 
   docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras


$ sudo rm -rf /var/lib/docker
$ sudo rm -rf /var/lib/containerd

Conclusion

You have now installed Docker Engine on your Linux machine successfully. In this comprehensive guide, you have learned how to install Docker from the APT repository, by downloading packages, and also using a convenience script.

You can choose the best approach suitable for your requirements. We have also explained the steps to completely uninstall Docker Engine in case you want to remove it or install a different version.

Frequently Asked Questions

Q1. Is Docker free for Linux?

Indeed, independent developers and enthusiasts can utilize Docker”s free Community Edition. All of the essential features for creating, executing, and maintaining containers are included in this edition.

The free edition of Docker is ideal for those just starting with Linux, while subscription plans come with extra features like private registries and enterprise support.

Q2. How much RAM do I need for Docker?

The complexity of the containers you run will determine how much Memory you need for Docker. Setting aside at least 2GB of RAM for basic Docker usage is a fair rule of thumb. But apps that use a lot of memory inside containers can need more.

Keep an eye on how much RAM your system is using and modify the allocation as necessary.

Q3. Is Docker a VM?

No, there are some significant differences between virtual machines (VMs) and Docker containers. Docker containers share the host”s kernel, but virtual machines (VMs) simulate a whole operating system. As a result, containers are lightweight and start up faster than virtual machines.

Consider virtual machines (VMs) as entire computers inside your computer, whereas containers are separate processes that share the same resources.

Q4. Is Docker good for beginners?

Although Docker has a learning curve, its fundamental ideas are quite simple. Online resources and tutorials geared towards beginners are abundant. Docker is useful for optimizing development processes because it can package apps and their dependencies into separate pieces.

Beginners can take advantage of Docker”s capabilities to improve their development experience with a little work.

Q5. Which is the best Linux OS for Docker?

The majority of popular Linux distributions, including Fedora, Ubuntu, Debian, and CentOS, have good Docker support. The “best” OS is determined by your comfort level and taste. Ubuntu is a well-liked option that is renowned for being user-friendly if you”re new to Linux.

In the end, Docker should be compatible with any current Linux distribution that has a robust package manager.


Advertisements

”;

Leave a Reply

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