Docker Installation

  1. First execute this following command to uninstall those packages which might conflict with the docker installation.
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

Untitled

  1. Now execute these commands to install docker and its dependencies.
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL <https://download.docker.com/linux/debian/gpg> -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \\
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] <https://download.docker.com/linux/debian> \\
  $(. /etc/os-release && echo "bookworm") stable" | \\
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

You might have to update the link on sudo curl -fsSL [<https://download.docker.com/linux/debian/gpg>](<https://download.docker.com/linux/debian/gpg>) -o /etc/apt/keyrings/docker.asc based on what Linux distro you are using. For me, I was using a Debian distro so I had to update it from this link https://download.docker.com/linux/. Check if your distro is present or not.

After that you have to change the version name $(. /etc/os-release && echo "bookworm") stable" |based on your distro’s version name. You have to go to distsfolder of your Linux distro to find what version is available for you and choose the version name based on your PC. For me it was debian and the version was bookworm.

Untitled

  1. Now execute the following command to install docker.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Untitled

  1. To check if docker was successfully installed or not download hello-world image and run.
sudo docker run hello-world

Untitled

If all the process goes right then it will show something like this. Now installation is complete.

Basic Docker Commands

  1. docker run: This command creates and starts a container based on a Docker image.