LochStudios  /  Help Centre  /  VPS & Linux  /  Install Docker and Docker Compose

Install Docker and Docker Compose

Install Docker Engine and Docker Compose on your Ubuntu/Debian VPS to containerize applications.

Updated

Docker lets you package applications into isolated containers that run consistently across any environment. Docker Compose simplifies managing multi-container setups. This guide covers installing both on Ubuntu/Debian; RHEL/CentOS users should replace apt with dnf or use Docker's official repository.

Prerequisites

  • Ubuntu 18.04+ or Debian 10+ (or equivalent RHEL/CentOS)
  • SSH access to your VPS
  • sudo privileges

Step 1: Update your package manager

sudo apt update && sudo apt upgrade -y

Step 2: Remove any old Docker installations (optional, if present)

sudo apt remove -y docker docker.io containerd runc

Step 3: Install required dependencies

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

Step 4: Add Docker's official GPG key

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

(For Debian, replace ubuntu with debian in the URL above.)

Step 5: Set up Docker's official repository

For Ubuntu:
CODE4

For Debian:
CODE5

Step 6: Update package lists and install Docker Engine

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

This installs Docker Engine, the CLI tools, containerd, and the Docker Compose plugin (v2, built into Docker).

Step 7: Verify Docker installation

docker --version
docker compose version

You should see version strings for both.

Step 8: Start and enable Docker daemon

sudo systemctl start docker
sudo systemctl enable docker

Step 9: Run a test container (optional)

sudo docker run hello-world

If you see "Hello from Docker!", the installation succeeded.

Step 10 (Optional): Allow your user to run Docker without sudo

sudo usermod -aG docker $USER
newgrp docker

Log out and back in for the group membership to take effect. After this, you can run docker commands without sudo.

Using Docker Compose

Create a docker-compose.yml file in your project directory:

version: '3.8'
services:
  web:
    image: nginx:latest
    ports:
      - "80:80"
  db:
    image: postgres:15
    environment:
      POSTGRES_PASSWORD: yourpassword
    volumes:
      - db_data:/var/lib/postgresql/data

volumes:
  db_data:

Start services:
CODE12

Stop services:
CODE13

Network ports

If your VPS is behind a firewall or security group, open the ports your containers expose (e.g., port 80 for web, port 5432 for PostgreSQL). Check your hosting provider's firewall documentation.

Tips

  • Image updates: Pull the latest images with docker pull <image> before redeploying.
  • Logs: View container logs with docker compose logs -f service-name.
  • Cleanup: Remove dangling images/containers with docker image prune and docker container prune.
  • Volumes: Store persistent data in Docker volumes, not ephemeral container storage.

Docker and Docker Compose are now ready for production workloads.


Was this article helpful?

← Back to VPS & Linux