Steps to Install Docker and Docker Compose on Debian 11:
Update the Package List:
sudo apt update
This command refreshes the local package index to ensure you are downloading the latest versions of the packages.
Install Required Packages:
sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common
These packages are necessary to allow your system to use repositories over HTTPS and to manage repository keys.
Add Docker’s Official GPG Key:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
This adds Docker’s GPG key to ensure that the packages are downloaded from a trusted source.
Set Up the Docker Repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
This adds Docker’s official stable repository to your system, ensuring you can download Docker from the correct source.
Update the Package List Again:
sudo apt update
Now that Docker’s repository has been added, this refreshes the package list to include Docker packages.
Check the Docker CE Package:
apt-cache policy docker-ce
This checks the availability of the docker-ce (Community Edition) package and ensures that it will be installed from the correct source.
Install Docker:
sudo apt install docker-ce
This installs Docker CE (Community Edition) on your system.
Check Docker Status:
sudo systemctl status docker
This command checks if Docker is running properly. You can use this command multiple times to verify that Docker is functioning correctly.
Install Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
This downloads the Docker Compose binary for your specific OS and architecture.
Make Docker Compose Executable:
sudo chmod +x /usr/local/bin/docker-compose
This grants execution permissions to the Docker Compose binary.
Create Docker Group:
sudo groupadd docker
This creates a new group called “docker,” which will allow users in this group to execute Docker commands without needing sudo.
Add User to Docker Group:
sudo usermod -aG docker $USER
This command adds the current user to the “docker” group, allowing them to run Docker without sudo.
Conclusion
Following these steps, you can successfully install and configure Docker and Docker Compose on Debian 11. This setup allows you to easily manage containers and multi-container applications without needing elevated permissions for every command.