This guide provides step-by-step instructions to install Docker on a Linux system, specifically focusing on Ubuntu. The steps may slightly vary for other distributions.
Open a terminal and update your existing list of packages:
sudo apt updateInstall the packages that allow apt to use repositories over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-commonAdd the GPG key for Docker’s official repository to your system:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -Add the Docker repository to APT sources:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"Update the package database with the Docker packages from the newly added repo:
sudo apt updateEnsure you are about to install from the Docker repo instead of the default Ubuntu repo:
apt-cache policy docker-ceInstall Docker:
sudo apt install docker-ceVerify that Docker is installed and running:
sudo systemctl status dockerTo avoid needing sudo for Docker commands, add your user to the docker group:
sudo usermod -aG docker ${USER}Log out and log back in to apply the group change.
Alternatively, you can use the following command to refresh group membership without logging out:
su - ${USER}Verify that your user is now added to the docker group:
groups ${USER}Verify the installation by running a test Docker container:
docker run hello-worldThis command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message.
If you encounter any issues during the installation, here are some common troubleshooting steps:
-
Ensure that the Docker service is running:
sudo systemctl start docker
-
Check Docker logs for errors:
sudo journalctl -u docker.service
-
Verify that your user is correctly added to the
dockergroup.