Docker is a powerful platform for building, shipping, and running applications inside containers. Below is a step-by-step guide for installing Docker on Ubuntu 18.04, along with troubleshooting tips for resolving dependency errors you may encounter.
Step 1: Update Packages and Install Prerequisites
First, update your system and install required dependencies:
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
Step 2: Add Docker’s Official GPG Key
Create a keyring directory and add Docker’s 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 3: Set Up the Docker Repository
Add the Docker repository to your sources list:
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
Then update your package index:
sudo apt-get update
Step 4: Install Docker
Now install Docker and related components:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Common Installation Error: Unmet Dependencies
During installation, you may encounter an error similar to this:
The following packages have unmet dependencies:
gsettings-desktop-schemas : Breaks: mutter (< 3.31.4) but 3.28.4+git20200505-0ubuntu18.04.2 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
This typically indicates missing or conflicting packages.
Step 5: Fixing the Error
To resolve this issue, install the missing dependencies:
sudo apt install gsettings-desktop-schemas
sudo apt install build-essential
Then retry installing Docker:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Step 6: Verify Docker Installation
Run the hello-world test container to confirm everything is working:
sudo docker run hello-world
If successful, you should see output similar to:
Hello from Docker!
This message shows that your installation appears to be working correctly.
This confirms that the Docker client and daemon are communicating properly.
Comments
Leave a Comment
No comments yet. Be the first to comment!