Start with docker and docker compose

How to install docker and docker compose on Debian 12

On a freshly installed Debian 12 do the followings commands:

Update and install dependencies

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

Configure the docker repository

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

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

Update the repository and install docker and compose

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

Test

sudo docker run hello-world

Use docker as non root user

Currently you can't use docker command without using sudo, to be able to do that you need to add your current user in the docker group. you can do that with the command:

 sudo usermod -aG docker $USER

Disconnect and reconnect your session and run

docker run hello-world

If you have no permission issue, you are good to go.

Source: