Installing Docker on Ubuntu: A Step-by-Step Guide ๐Ÿš€(with Debugg)

Written by:

Docker simplifies application deployment by packaging software into containers

Here’s how to install Docker on Ubuntu efficiently:



1. Uninstall Old Versions

Remove any previous Docker installations to avoid conflicts

sudo apt-get remove docker docker-engine docker.io containerd runc

This ensures a clean environment for the new installation



2. Set Up Docker’s Official Repository

a. Install Prerequisite Packages

Ensure apt can use repositories over HTTPS

sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg

b. Add Dockerโ€™s GPG Key

Add Docker’s official GPG key to verify package authenticity

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo tee /etc/apt/keyrings/docker.asc > /dev/null
sudo chmod a+r /etc/apt/keyrings/docker.asc

c. Set Up the Stable Repository

Add Docker’s repository to your sources list

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Then, update the package index

sudo apt-get update


3. Install Docker Engine

Install Docker Engine and associated components

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

This command installs:

  • docker-ce: Docker Engine
  • docker-ce-cli: Command-line interface for Docker
  • containerd.io: Container runtime
  • docker-buildx-plugin: Docker Build
  • docker-compose-plugin: Docker Compos


4. Verify Installation

a. Check Docker Version

Confirm the installation by checking the Docker version

docker --version

b. Run a Test Container

Run the “Hello World” container to verify Docker is functioning correctly

sudo docker run hello-world

This command downloads and runs a test image, outputting a confirmation message upon success



5. Manage Docker as a Non-Root User

To run Docker commands without sudo

a. Create Docker Group

Create the Docker group if it doesn’t already exist

sudo groupadd docker

b. Add User to Docker Group

Add your user to the Docker group

sudo usermod -aG docker $USER

c. Apply Group Changes

Log out and log back in to apply the group changes. Alternatively, use

newgrp docker

d. Verify Non-Root Access

Run the “Hello World” container without sudo

docker run hello-world
If successful, Docker is configured for non-root usage


Troubleshooting Common Issues

a. Permission Denied While Accessing Docker Socket

Error:

  • Got permission denied while trying to connect to the Docker daemon socket

Solution:

  • Ensure your user is added to the Docker group
  • Verify group membership with
groups $USER
  • If the issue persists, adjust the ownership of the Docker directory
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R

b. Docker Daemon Not Running

Error:

  • Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Solution:

  • Start the Docker service
sudo systemctl start docker

  • Enable Docker to start on boot
sudo systemctl enable docker

c. Old Versions of Docker Installed

Issue:

  • Conflicts with previous Docker installations

Solution:

  • Uninstall old Docker versions
sudo apt-get remove docker docker-engine docker.io containerd runc
  • Then, proceed with the installation steps above

d. Network Connectivity Issues

Error:

  • Failed to fetch errors during “apt-get update”

Solution:

  • Check your internet connection –
  • Ensure your system’s DNS settings are correctly configured



By following these steps, you should have Docker successfully installed on your Ubuntu systemFor more detailed information, refer to the [official Docker documentation]

Reference Link: (https://docs.docker.com/engine/install/ubuntu/


Discover more from DIYLABHub.com

Subscribe to get the latest posts sent to your email.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

google.com, pub-5998895780889630, DIRECT, f08c47fec0942fa0