Deploying Docker and Docker Compose on Debian/Ubuntu Environments

Containerization allows you to isolate applications and their dependencies, ensuring consistency across development and production environments. On a Hovixa VPS, Docker provides the runtime for these containers, while Docker Compose simplifies the management of multi-container applications (like a WordPress site with a separate MySQL container). This guide covers the installation using the official Docker repositories to ensure you receive the latest security patches.

1. Preparing the System

Before installing Docker, remove any older versions that might conflict with the official Docker Engine packages. Then, install the necessary dependencies for HTTPS-based repository management.

# Uninstall old versions
sudo apt-get remove docker docker-engine docker.io containerd runc

# Install prerequisites
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
    

2. Setting Up the Official Repository

Using the official Docker GPG key and repository ensures package integrity and allows for seamless updates via apt.

# Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

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

3. Installing Docker Engine and Compose

With the repository configured, you can install the Docker Engine, the CLI, and the Docker Compose plugin in a single command.

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

4. Post-Installation: Rootless Management

By default, the Docker daemon binds to a Unix socket owned by root. To avoid using sudo for every command, add your user to the docker group.

sudo usermod -aG docker $USER
# Activate the changes to groups
newgrp docker
    

5. Deployment Comparison Table

Component Role Primary Command
Docker Engine The core runtime for running containers. `docker run`
Docker Compose Orchestrator for multi-container apps via YAML. `docker compose up`
Containerd The daemon managing the container lifecycle. Managed by Docker

6. Technical Implementation Details

  • Storage Driver: Docker on Debian/Ubuntu typically uses the overlay2 storage driver. This is highly optimized for the Hovixa NVMe storage layer, providing excellent read/write performance for container layers.
  • Networking: Docker creates a virtual bridge (docker0). Ensure your UFW settings allow traffic from this interface if your containers need to communicate with services hosted directly on the VPS.
  • Docker Compose V2: Note that modern installations use docker compose (plugin) rather than the legacy docker-compose (standalone python script). The syntax is largely identical, but the performance is improved.

Sysadmin Advice: Use **docker system prune** monthly to remove dangling images and stopped containers. On a VPS with limited NVMe, accumulated Docker layers can quickly consume gigabytes of storage if not monitored.

Hjalp dette svar dig? 0 Kunder som kunne bruge dette svar (0 Stem)