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 update
Install the packages that allow apt to use repositories over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Add 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 update
Ensure you are about to install from the Docker repo instead of the default Ubuntu repo:
apt-cache policy docker-ce
Install Docker:
sudo apt install docker-ce
Verify that Docker is installed and running:
sudo systemctl status docker
To 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-world
This 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
docker
group.