Docker Setup
This tutorial covers how to install and configure Docker on your GoMami VPS for containerized application deployment.
Prerequisites
- A deployed VPS instance (Ubuntu 24.04 LTS recommended)
- SSH access to your server
- At least 1 GB of memory
Install Docker
Ubuntu / Debian
# Update packages
apt update
# Install dependencies
apt install -y ca-certificates curl gnupg
# Add Docker's official GPG key
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
# Add Docker repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker
apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Verify installation
docker --version
docker compose version
CentOS / AlmaLinux
# Install dependencies
dnf install -y yum-utils
# Add Docker repository
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# Install Docker
dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Start and enable on boot
systemctl start docker
systemctl enable docker
Verify Installation
# Run test container
docker run hello-world
# View Docker info
docker info
Configure Docker Mirror (Optional)
If pulling images from Docker Hub is slow, configure a mirror:
mkdir -p /etc/docker
cat > /etc/docker/daemon.json << 'EOF'
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com"
],
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
EOF
# Restart Docker
systemctl daemon-reload
systemctl restart docker
tip
GoMami's Asia-Pacific nodes have low latency to international networks, so Docker Hub speeds are usually fine. Skip mirror configuration if pull speeds are acceptable.
Common Docker Commands
# Pull image
docker pull nginx:latest
# Run container
docker run -d --name my-nginx -p 80:80 nginx
# List running containers
docker ps
# View container logs
docker logs my-nginx
# Enter container
docker exec -it my-nginx /bin/bash
# Stop container
docker stop my-nginx
# Remove container
docker rm my-nginx
# List images
docker images
Docker Compose Example
Deploy multi-container apps with Docker Compose. Here's an Nginx + MySQL example:
# docker-compose.yml
services:
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./html:/usr/share/nginx/html
restart: unless-stopped
db:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: your_secure_password
MYSQL_DATABASE: myapp
volumes:
- mysql_data:/var/lib/mysql
restart: unless-stopped
volumes:
mysql_data:
# Start all services
docker compose up -d
# View service status
docker compose ps
# View logs
docker compose logs -f
# Stop all services
docker compose down
Resource Limits
Set resource limits to prevent a single container from consuming too many resources:
# Limit memory and CPU
docker run -d \
--name my-app \
--memory="512m" \
--cpus="1.0" \
my-app-image
caution
VPS memory and CPU are limited. When running multiple containers, allocate resources carefully and leave enough for system overhead.
Next Steps
- Deploy Web Server — Deploy websites with Nginx
- Security Hardening — Harden server security