Docker is a platform for building, shipping, and running applications in containers — lightweight, portable environments that include everything your application needs. Docker Compose extends Docker by letting you define and run multi-container applications with a single configuration file. This guide shows you how to install both on your Data Mammoth VPS.
Prerequisites
- A Data Mammoth VPS running Ubuntu 22.04/24.04, Debian 12, or CentOS/AlmaLinux.
- SSH access with sudo privileges.
- At least 1 GB of RAM (2 GB or more recommended for production workloads).
Installing Docker on Ubuntu / Debian
Step 1 — Remove Old Versions
Remove any previously installed Docker packages:
sudo apt remove docker docker-engine docker.io containerd runc 2>/dev/nullStep 2 — Install Prerequisites
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-releaseStep 3 — Add Docker's Official GPG Key and Repository
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.gpgAdd the repository (for Ubuntu):
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullFor Debian, replace ubuntu with debian in the URL above.
Step 4 — Install Docker Engine
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginStep 5 — Verify the Installation
sudo docker run hello-worldYou should see a message confirming Docker is installed correctly.
Installing Docker on CentOS / AlmaLinux
Step 1 — Remove Old Versions
sudo dnf remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine 2>/dev/nullStep 2 — Add Docker Repository
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repoStep 3 — Install Docker Engine
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginStep 4 — Start and Enable Docker
sudo systemctl start docker
sudo systemctl enable dockerStep 5 — Verify
sudo docker run hello-worldPost-Installation Setup
Run Docker Without Sudo
By default, Docker commands require sudo. To run Docker as a non-root user, add your user to the docker group:
sudo usermod -aG docker $USERLog out and log back in for the change to take effect. Verify:
docker run hello-worldSecurity note: Adding a user to the docker group grants root-equivalent privileges through Docker. Only add trusted users.
Configure Docker to Start on Boot
Docker should start automatically on boot by default, but verify:
sudo systemctl enable docker
sudo systemctl enable containerdUsing Docker Compose
Docker Compose is now included as a Docker plugin (no separate installation needed). Use the docker compose command (with a space, not a hyphen):
docker compose versionCreating a Docker Compose File
Create a project directory and a docker-compose.yml file:
mkdir ~/myapp && cd ~/myapp
nano docker-compose.ymlExample — a simple web application with a database:
version: '3.8'services: web: image: nginx:latest ports: - "80:80" volumes: - ./html:/usr/share/nginx/html depends_on: - db restart: unless-stopped
db: image: mysql:8.0 environment: MYSQL_ROOT_PASSWORD: your_secure_password MYSQL_DATABASE: myapp MYSQL_USER: appuser MYSQL_PASSWORD: your_app_password volumes: - db_data:/var/lib/mysql restart: unless-stopped
volumes: db_data:
Basic Docker Compose Commands
# Start all services in the background
docker compose up -dView running containers
docker compose psView logs
docker compose logs -fStop all services
docker compose downRebuild and restart
docker compose up -d --buildStop and remove volumes (deletes data)
docker compose down -vEssential Docker Commands
# List running containers
docker psList all containers (including stopped)
docker ps -aView container logs
docker logs <container_name>Execute a command inside a container
docker exec -it <container_name> bashPull an image
docker pull nginx:latestRemove stopped containers
docker container pruneRemove unused images
docker image pruneView disk usage
docker system dfClean up everything unused
docker system prune -aDocker Storage and Disk Management
Docker images, containers, and volumes can consume significant disk space. Monitor usage with:
docker system dfTo free up space:
# Remove stopped containers
docker container prune -fRemove unused images
docker image prune -a -fRemove unused volumes (careful — this deletes data)
docker volume prune -fSchedule regular cleanups if you frequently build and deploy containers.
Docker Networking
Docker creates its own network bridge by default. Containers on the same Docker Compose project can communicate using service names as hostnames.
# List Docker networks
docker network lsInspect a network
docker network inspect bridgeSecurity Best Practices
USER directive in Dockerfiles.services:
web:
image: nginx
deploy:
resources:
limits:
cpus: '0.5'
memory: 512MFirewall Configuration for Docker
Docker modifies iptables rules directly, which can bypass UFW or firewalld. To prevent Docker from exposing ports unintentionally:
sudo nano /etc/docker/daemon.jsonAdd:
{
"iptables": false
}Restart Docker:
sudo systemctl restart dockerThen manually manage port access through your firewall. See Server Firewall Hardening Guide.
What to Do Next
- Installing n8n from the Marketplace — Deploy n8n with Docker.
- How to Install an App on Your Server — Install marketplace apps.
- Backup Strategy — Snapshots, Offsite, Automated — Back up your Docker volumes.
- Monitoring Server Performance — Monitor container resource usage.