zh
Docker VPS托管:离岸服务器容器化部署指南
Docker容器化技术彻底改变了应用部署方式,通过将应用及其依赖打包成独立容器,实现了从开发到生产的环境一致性。在离岸VPS上运行Docker意味着完整的容器编排控制权,结合Anubiz Host冰岛VPS的高性能基础设施,是构建现代化、可扩展应用架构的理想方案。
Need this done for your project?
We implement, you ship. Async, documented, done in days.
在VPS上安装Docker
在Ubuntu/Debian VPS上安装最新版Docker Engine:
apt update
apt install -y ca-certificates curl gnupg lsb-release
# 添加Docker官方GPG密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# 添加Docker APT源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list
apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
systemctl enable docker
docker --version
docker compose version
将当前用户加入docker组(避免每次使用sudo):
usermod -aG docker $USERDocker Compose多服务编排
Docker Compose是在单台VPS上管理多容器应用的最佳工具。以下是一个典型的Web应用stack配置:
# docker-compose.yml
version: '3.8'
services:
app:
build: .
container_name: webapp
restart: always
environment:
- NODE_ENV=production
- DATABASE_URL=postgresql://user:pass@db:5432/mydb
ports:
- "127.0.0.1:3000:3000"
depends_on:
- db
- redis
db:
image: postgres:16-alpine
container_name: postgres
restart: always
environment:
POSTGRES_DB: mydb
POSTGRES_USER: user
POSTGRES_PASSWORD: strongpassword
volumes:
- pgdata:/var/lib/postgresql/data
redis:
image: redis:7-alpine
container_name: redis
restart: always
volumes:
pgdata:
docker compose up -d
docker compose ps
docker compose logs -f appNginx反向代理与SSL
使用Nginx作为Docker容器的外部入口,处理SSL终止和流量路由:
apt install -y nginx certbot python3-certbot-nginx
nano /etc/nginx/sites-available/docker-app
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
ln -s /etc/nginx/sites-available/docker-app /etc/nginx/sites-enabled/
certbot --nginx -d yourdomain.com
systemctl reload nginx
另一种方案是使用Traefik作为Docker原生反向代理,通过容器标签自动发现服务并申请Let's Encrypt证书,适合管理多个Docker应用的场景。Docker数据持久化与备份
容器的无状态特性要求数据持久化通过Docker卷实现。在Anubiz Host VPS上管理Docker卷的最佳实践:
# 查看所有卷
docker volume ls
# 备份PostgreSQL数据卷
docker exec postgres pg_dump -U user mydb | gzip > backup_$(date +%Y%m%d).sql.gz
# 将备份文件同步到安全位置
rsync -avz backup_*.sql.gz user@backup-server:/backups/
配置自动每日备份的crontab:
0 2 * * * docker exec postgres pg_dump -U user mydb | gzip > /var/backups/db_$(date +%Y%m%d).sql.gz
Docker的只读卷挂载可提升安全性,将配置文件以只读方式挂载到容器:
volumes:
- ./config:/app/config:ro
- ./data:/app/data:rw
定期清理未使用的镜像、容器和卷以释放磁盘空间:
docker system prune -a --volumesRelated Services
Why Anubiz Host
100% async — no calls, no meetings
Delivered in days, not weeks
Full documentation included
Production-grade from day one
Security-first approach
Post-delivery support included
Ready to get started?
Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.