Introduction / Why This Is Needed
Docker is an application containerization platform that allows you to package programs and their dependencies into portable containers. Installing Docker on Ubuntu will give you the ability to:
- Deploy and run applications in isolated environments.
- Simplify the development, testing, and deployment process.
- Use ready-made images from Docker Hub (millions of containers).
After completing this guide, you will have a working Docker Engine environment, ready for development or production tasks.
Requirements / Preparation
Before you begin, ensure that:
- You have Ubuntu 18.04, 20.04, or 22.04 LTS installed.
- You have access to an account with sudo privileges.
- The system is updated (it is recommended to run
sudo apt update && sudo apt upgrade).
⚠️ Important: Installing Docker on Ubuntu requires administrator privileges. All commands below assume the use of
sudo.
Step-by-Step Instructions
Step 1: Update Package Cache
Update the local package cache to get information about the latest versions:
sudo apt update
Step 2: Install Dependencies
Install packages necessary for adding third-party repositories:
sudo apt install -y ca-certificates curl gnupg lsb-release
Step 3: Add the Official Docker GPG Key
Create a directory for keys and add Docker's official GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Step 4: Add the Docker Repository
Add the Docker repository to sources.list. Use the command corresponding to your Ubuntu version:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 5: Install Docker Engine
Update the cache again and install Docker:
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 6: Start and Enable Autostart
Start the Docker service and configure it to start automatically on system boot:
sudo systemctl start docker
sudo systemctl enable docker
Step 7: Verify the Installation
Run the hello-world test container to verify the installation is correct:
sudo docker run hello-world
If you see a welcome message, Docker is installed correctly.
Step 8: Configure Permissions (Optional)
By default, Docker commands require sudo. To run Docker as a regular user, add them to the docker group:
sudo usermod -aG docker $USER
💡 Tip: After running this command, log out of your session and log back in (or reboot) for the changes to take effect.
Verification
- Check Docker version:
docker --version
The Docker Engine version should be displayed (e.g.,Docker version 24.0.7, build afdd53b). - Check service status:
sudo systemctl status docker
The status should beactive (running). - Run a container without sudo (if Step 8 was completed):
docker run hello-world
If the container runs without access errors, the permission configuration was successful.
Potential Issues
Error: docker: command not found
- Cause: Docker is not installed or the executable path is not added to
PATH. - Solution: Ensure the installation steps were performed correctly. Restart the terminal or run
source ~/.bashrc.
Error: Got permission denied while trying to connect to the Docker daemon socket
- Cause: The current user is not a member of the
dockergroup. - Solution: Complete Step 8 (add to group) and log out and back into the system.
GPG Error When Adding Repository
- Cause: The GPG key is missing or corrupted.
- Solution: Repeat Step 3, ensuring the command completes without errors. Check for the existence of the file
/etc/apt/keyrings/docker.gpg.
Ubuntu Version Conflict in Repository
- Cause: The repository addition command uses
$(lsb_release -cs), which may return a codename not supported by the Docker repository (e.g., for Ubuntu test builds). - Solution: Explicitly specify the LTS codename (e.g.,
jammyfor Ubuntu 22.04) in the repository string instead of$(lsb_release -cs).
No Space Left on Device
- Cause: Docker and its images require free disk space.
- Solution: Clean up unused images:
docker system prune -a. Ensure there is sufficient space in the/var/lib/dockerpartition.