DevOpsDockerHow To

How To Install Docker on Debian, Ubuntu 18.04, 18.10, 20.4, & 22.04

Docker installation on Debian based operating system like Ubuntu

In this article, we are going to explain the steps for installing Docker on the Debian-based Ubuntu 64-bit operating system in detail. The user should have access to shell with sudo root user permission to perform installation steps.

Prerequisites

Ubuntu 18.04, 20.4 or 22.04 server with sudo access and external connectivity.

Sometimes, the Docker package is preinstalled, which does not work as expected due to missing dependencies. Therefore, all such existing Docker and related packages should be removed.

sudo apt-get purge docker lxc-docker docker-engine docker.io

Update package index file.

sudo apt update

Install Docker prerequisites packages

sudo apt install apt-transport-https ca-certificates curl software-properties-common

Add Docker repository GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add official Docker repository

If you’re using ARM64 instead of AMD64 replace [arch=amd64] with [arch=arm64]

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

The $(lsb_release -cs) provides the short code name of the distribution. In this case, the code name is Bionic. This helps to map the Docker repository to correct distribution and avoid any issues.

Install Docker

After adding the official Docker repository, update the package index files and install Docker.

sudo apt update
sudo apt install docker-ce

Verify if Docker service has started

sudo systemctl status docker

If the Docker service is not running then start the service using following command:

sudo systemctl start docker
sudo systemctl status docker

Execute docker command without sudo (optional)

By default, only the root user or a user in the docker group which is formed automatically during Docker installation may execute the docker command. An output similar to this may appear if you try to run the docker command without first prefixing it with sudo or without being a member of the docker group:

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

Add your username to the docker group to prevent having to type sudo each time you execute the docker command:

sudo gpasswd -a $USER docker

In this command, the username will be taken from the current shell envrionment variable, and the group name will be docker. After successful execution of the command, logout and login with the user for changes to take effect, or execute the following command to skip re-logging in.

newgrp docker

Verify your user is added to the docker group using command:

id -nG

Check by running any docker command. Here, I am checking the various commands available in Docker and then executing a command to check the version of Docker installed on the operating system.

docker

Output:

  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes
geeks@terminal:~$ docker --version

There are various ways other than those specified above to install Docker on Debian-based distributions, as shown in the below links:

Debian - https://docs.docker.com/install/linux/docker-ce/debian/
Ubuntu - https://docs.docker.com/install/linux/docker-ce/ubuntu/

That's all folks!

Related Articles

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Back to top button