Blog / Linux/ Complete Guide to Installing Docker, Docker Compose, and Ansible on Debian 10

Complete Guide to Installing Docker, Docker Compose, and Ansible on Debian 10

Debian 10 安装 Docker、Docker Compose 与 Ansible 完整指南

Introduction

This guide provides a complete walkthrough for installing the Docker container engine, Docker Compose orchestration tool, and Ansible automation tool on Debian 10 (Buster). Commands and explanations have been updated to reflect current best practices.

Installing Docker Engine

1. Remove Old Versions (If Any)

If older Docker packages (e.g., docker, docker.io, docker-engine) are present, remove them first.

sudo apt-get remove docker docker-engine docker.io containerd runc

2. Install Required Packages

Update the package index and install packages to allow apt to use a repository over HTTPS.

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

3. Add Docker's Official GPG Key

Add Docker's GPG key to verify package integrity.

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

4. Verify the Key Fingerprint

Verify that the key fingerprint ends with 0EBFCD88.

sudo apt-key fingerprint 0EBFCD88

The output should contain 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88.

5. Set Up the Stable Repository

Add the Docker stable repository to your APT sources.

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

6. Install Docker Engine

Update the package index and install the latest version of Docker Engine, CLI, and Containerd.

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

Docker's default installation path is /var/lib/docker.

7. Install a Specific Version (Optional)

To install a specific version of Docker Engine:

  1. List available versions:
    apt-cache madison docker-ce
  2. Install the chosen version (replace <VERSION_STRING> with the version from the previous step, e.g., 5:20.10.7~3-0~debian-buster):
    sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

8. Verify Installation

Run the Hello World image to test Docker and check the installed version.

sudo docker run hello-world
docker --version

9. Manage Docker Service

Enable or disable Docker to start on boot.

sudo systemctl enable docker  # Enable on boot
sudo systemctl disable docker # Disable on boot

For advanced configuration (like running Docker as a non-root user), refer to the official documentation.

Installing Docker Compose

Docker Compose is a tool for defining and running multi-container Docker applications. It's recommended to download the latest stable version from its GitHub releases page.

Important: The version 1.27.3 mentioned in some older guides is outdated. Visit the Docker Compose GitHub Releases page to find the latest version and replace v2.20.0 in the commands below accordingly.

# Download Docker Compose binary (example uses v2.20.0, replace with latest)
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# Apply executable permissions
sudo chmod +x /usr/local/bin/docker-compose

# Verify installation
docker-compose --version

Successful installation will output something like Docker Compose version v2.20.0.

Installing Ansible

Ansible is a powerful automation tool. On Debian 10, it can be installed directly from the system repositories.

sudo apt update
sudo apt install ansible -y
ansible --version

After installation, run ansible --version to confirm the installed version.

Conclusion

You have now successfully installed the Docker platform, Docker Compose orchestration tool, and Ansible automation tool on Debian 10. This combination provides a powerful foundation for building, deploying, and managing modern applications.

Recommended next steps:

  • Add your user to the docker group to run Docker commands without sudo: sudo usermod -aG docker $USER (requires re-login).
  • Consult the official Docker and Ansible documentation for in-depth features and best practices.

Post a Comment

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