Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Installing Docker & Docker Compose

Why Docker?

Docker makes it easy to deploy and manage:

  • NextCloud
  • Your React websites
  • Any other services
  • Everything isolated and reproducible

Step 1: Remove Old Docker Versions (if any)

apt remove docker docker-engine docker.io containerd runc 2>/dev/null || true

Step 2: Install Prerequisites

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

Step 3: Add Docker’s Official GPG Key

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

Step 4: Add Docker Repository

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

Step 5: Update Package Index

apt update

Step 6: Install Docker Engine & Docker Compose

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

Step 7: Verify Docker Installation

docker --version

Should show something like:

Docker version 24.0.x, build xxxxx
docker compose version

Should show:

Docker Compose version v2.x.x

Step 8: Test Docker

Run the hello-world container:

docker run hello-world

Expected output:

Hello from Docker!
This message shows that your installation appears to be working correctly.

Step 9: Enable Docker to Start on Boot

systemctl enable docker
systemctl enable containerd

Step 10: Check Docker Service Status

systemctl status docker

Should show active (running).

Optional: Add Non-Root User to Docker Group

If you created a non-root user (myUser), add them to docker group:

usermod -aG docker myUser

Now myUser can run docker commands without sudo.

Note: User needs to log out and back in for this to take effect.

Quick Docker Commands Reference

# List running containers
docker ps

# List all containers (including stopped)
docker ps -a

# List images
docker images

# Stop a container
docker stop CONTAINER_NAME

# Remove a container
docker rm CONTAINER_NAME

# View logs
docker logs CONTAINER_NAME

# Docker Compose commands
docker compose up -d          # Start services
docker compose down           # Stop services
docker compose logs -f        # View logs
docker compose ps             # List services

Directory Structure Setup

Let’s create a good directory structure for your services:

mkdir -p /opt/docker
cd /opt/docker

Create directories for each service:

mkdir -p nextcloud
mkdir -p react-sites
mkdir -p reverse-proxy
mkdir -p wireguard
mkdir -p backups

Check structure:

tree -L 1 /opt/docker

Should show:

/opt/docker
├── backups
├── nextcloud
├── react-sites
├── reverse-proxy
└── wireguard