π Installing Docker on an Ubuntu System#
Docker is a powerful platform for developing, shipping, and running applications in containers. This guide will walk you through setting up Docker’s apt repository and installing it on an Ubuntu system.
β Prerequisites#
- π₯οΈ Ubuntu 20.04+ (or a later version)
- π User account with sudo privileges
- π Stable internet connection
π Step 1: Update Package Index#
First, update the package list to ensure you have the latest information:
sudo apt-get update && sudo apt-get upgrade -y
π¦ Step 2: Install Required Dependencies#
Install necessary packages to allow apt to use a repository over HTTPS:
sudo apt-get install -y ca-certificates curl
π Step 3: Add Dockerβs Official GPG Key#
Set up the directory for key storage, download Dockerβs official GPG key, and set correct permissions:
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
π Step 4: Add the Repository to Apt Sources#
Add Dockerβs stable repository to your systemβs package sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update the package list again:
sudo apt-get update
π οΈ Step 5: Install Docker Engine#
To install the latest version of Docker, run:
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
π Step 6: Verify Docker Installation#
Check if Docker is installed correctly by running:
docker --version
To test if Docker is working properly, run the hello-world container:
sudo docker run hello-world
π€ Step 7: Manage Docker as a Non-Root User (Optional)#
To avoid using sudo
every time you run Docker, add your user to the docker
group:
sudo usermod -aG docker $USER
Log out and back in, or run:
newgrp docker
π Step 8: Enable Docker to Start on Boot#
Ensure Docker starts automatically on system boot:
sudo systemctl enable docker && sudo systemctl start docker
β Uninstalling Docker (If Needed)#
If you need to remove Docker, use the following command:
sudo apt-get remove -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && sudo apt-get autoremove -y
If you also want to delete all Docker data (containers, images, volumes, etc.), run:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
This will completely remove Docker from your system.
π Conclusion#
You have successfully installed Docker on your Ubuntu system. You can now start using Docker to create, manage, and run containers efficiently. π’π³
π For more information, visit the official Docker documentation:
π Docker Installation Guide