Skip to content

How to install Docker and Docker Compose?

Download and run the Docker install script.

When you run the following command in your terminal, it downloads the official Docker installation script from the Docker website. Immediately after the download, the script is executed, which then installs Docker on your Linux system, automatically detecting and configuring it for your specific Linux distribution.

bash
curl -sSL https://get.docker.com | sh

Add the current user to the Docker group.

After the script finishes installing Docker, you have the option to add your user to the Docker group. This step is not required, but it's recommended because it allows you to run Docker commands without needing to use sudo privileges. To do this, run the following command:

bash
sudo usermod -aG docker $(whoami)

WARNING

Managing docker as a non-root user can be a security risk, read more here.

Applying the newly added group.

After adding yourself to the Docker group, you need to apply the changes. To do this, you have two options:

  1. Run the command below in your terminal.
  2. Alternatively, you can simply log out of your current session and log back in. This will also apply the changes.

Either of these steps will ensure that the changes take effect and you can start using Docker without sudo privileges.

bash
newgrp docker

Test if everything is correct.

To test that Docker is installed and configured correctly, run the following command in your terminal:

bash
docker run hello-world

If you didn't add yourself to the Docker group in the previous steps, you'll need to use sudo privileges to run this command. In that case, run:

bash
sudo docker run hello-world

TLDR

here is a one-liner:

Details
bash
curl -sSL https://get.docker.com | sh && sudo usermod -aG docker $(whoami) && newgrp docker && docker run hello-world

WARNING

Always verify a command before running it!