How To Install Docker Latest Version on Debian 11

Docker is the most known container technology, which is used by a lot of developers, SRE, DevOps, etc. In the Linux repository, they usually ship the docker packages, but mostly the outdated ones. That is why we prefer the packages provided by Docker itself, which updated instantly after the latest version release.

Docker can be used for almost anything, from building a simple app to building a cluster that can be powered by Docker Swarm or Kubernetes. Let’s start installing docker from scratch

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

Add official PGP key

We need to add PGP key, so we know it’s the authentic packages that signed with trusted key from the official docker repository

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Add Docker Repository

Add the official docker repository, this is the most preferred way because of the docker from the Debian repository is not up to date.

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker

Finally, time to install the docker itself

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y

Run Docker As Non-Previleges User

By default docker is only able to run as the root user, which is not recommended because it can go south, because the wrong command or delete some unrelated files/folder. That is why we run docker by a user, which is normally your user.

sudo usermod -a -G docker YOURUSER
# example
sudo usermod -a -G docker jack

before being able to run the docker, you’ll restart first.

sudo reboot

Verify Docker Running

Verify the installation of docker run smoothly, by running docker info

docker info
# output
...
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.6.3-docker)
  scan: Docker Scan (Docker Inc., v0.9.0)
 
Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.11
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
...

Test pull images from Docker Hub

docker pull nginx:latest

Build simple Docker image, create a Dockerfile file

FROM nginx:latest
CMD ["echo", "Hello World!"]

the build using docker build

docker build . -t testdocker

docker testing build success
run the docker images, which we build earlier

docker run testdocker:latest

That’s it, the docker running well, it can build the docker file and connection okay. For the latest step is to remove the testdocker, to clean up a little bit space

docker rmi testdocker -f

Leave a Comment