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.
curl -sSL https://get.docker.com | shAdd 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:
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:
- Run the command below in your terminal.
- 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.
newgrp dockerTest if everything is correct.
To test that Docker is installed and configured correctly, run the following command in your terminal:
docker run hello-worldIf 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:
sudo docker run hello-worldTLDR
here is a one-liner:
Details
curl -sSL https://get.docker.com | sh && sudo usermod -aG docker $(whoami) && newgrp docker && docker run hello-worldWARNING
Always verify a command before running it!