Install Docker and Docker Compose in Linux (Ultimate Guide)

Linux TLDR
Last Updated:
Reading time: 4 minutes

This article intends to focus on what Docker and Docker Compose are, their usage and drawbacks, and how to install them in major Linux distributions.

Tutorial Details

DescriptionDocker and Docker Compose
Difficulty LevelModerate
Root or Sudo PrivilegesYes
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisites
Internet RequiredYes

What is Docker?

If you are familiar with virtualization technologies like VMware or VirtualBox, then understanding the workings of Docker technology will be easier.

For your note, let’s focus on two main differences between both of these technologies:

  • Virtualization technologies are mostly used to create a completely separate environment (with a separate kernel) in which you can play with a real but virtualized system. Docker, on the other hand, also gives you a separate environment (but shares the host kernel) in command-line interfaces (reducing the size) and is helpful for making isolated applications.
  • Another difference between them is that the virtualization technology uses dedicated system resources, while Docker shares the host system resources, putting less strain on the system.

The following is a visual representation of the above differences:

Docker vs. Virtual System
📝
There are multiple differences between them that you can dig up on the internet.

What is Docker Compose?

Docker compose is a separate tool often used to run or handle multiple Docker containers at once. For example, you can separate your Web application and database into different Docker containers but link or handle them using a single command with Docker compose.

It allows users to define and configure all the services and configurations (like network, port, storage, caches, etc.) required by an application in a single file, then start and stop those services with a single command.

Usage of Docker

Virtualization technologies and Docker both have their own advantages and use cases. You can use them in different scenarios based on your needs, for example.

Use virtual machines when:

  • You want to run the entire operating system, with its own kernel and drivers.
  • You want to run applications that work on a specific operating system version.
  • You want to run multiple operating systems or versions on a single host machine.
  • You want to run applications that need direct access to hardware.
  • You want to test malicious applications as a security analyst, as this technology provides strong isolation and prevents any damage to your host system.

Use Docker when:

  • You want to deploy and run applications in an environment that is light and easy to move around so that you can use them on different machines.
  • You want to put less strain on your system, as Docker shares the same system resources as your host.
  • You want to quickly deploy or stop the application, or scale it up and down as needed, as Docker is designed to handle this task efficiently.

After knowing all the advantages of Docker, if you want to give it a try, then follow the next section to learn about its installation.

How to Install Docker and Docker Compose in Linux

The installation of Docker and Docker Compose varies for different distributions. In this article, you will find the steps to install it in major Linux distributions, starting with…

Installing Docker and Docker Compose in a Debian or Ubuntu System

1. Open your terminal and use the following command to update and install the necessary packages:

$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release

2. Add the Docker GPG key:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

3. Add the Docker repository:

$ echo "deb [arch=amd64 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

4. Update the package information and install Docker:

$ sudo apt update
$ sudo apt install docker-ce docker-ce-cli containerd.io

5. Check that Docker is successfully installed by pulling and running the ‘hello-world‘ container:

$ sudo docker run hello-world

6. Install Docker Compose:

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

7. Verify that Docker Compose is installed by running the following command:

$ docker-compose --version

That’s all it takes to install Docker and Docker Compose in Debian or Ubuntu based distributions.

Installing Docker and Docker Compose in a Red Hat or Fedora System

1. Install Docker using the following command:

$ sudo dnf install docker-ce

2. Start and enable the Docker service (or daemons):

$ sudo systemctl start docker
$ sudo systemctl enable docker

3. Add the existing user to the ‘docker‘ group with the usermod command to avoid using sudo in front of each docker command:

$ sudo usermod -aG docker $USER

4. Install Docker Compose using the following command:

$ sudo dnf install docker-compose

5. Verify that Docker and Docker Compose are correctly installed in your system by running the following command:

$ docker --version
$ docker-compose --version

The above command will output their current installed version on your terminal screen.

Installing Docker and Docker Compose in a Arch or Manjaro System

1. Update the system repository:

$ sudo pacman -Syu

2. Install Docker by running the following command:

$ sudo pacman -S docker

3. Start and enable the Docker service (or daemons):

$ sudo systemctl start docker
$ sudo systemctl enable docker

4. Install Docker Compose by running the following command:

$ sudo pacman -S docker-compose

5. Verify the Docker and Docker Compose installations:

$ docker --version
$ docker-compose --version

Congratulations! You have successfully installed Docker and Docker Compose in your Arch or Manjaro based distributions.

Final Word

Once the installation is complete, you can pull different images from the Docker hub and test them on your system.

If you want me to write more articles on Docker, do let me know in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.