Docker Compose allows developers to define and manage multiple application services through a single YAML configuration file. Web servers, API backends, databases, and caching services can operate in separate containers while communicating through controlled virtual networks.
Deploying Docker Compose microservices on a South Korea VPS provides an independent operating system environment with administrative access, configurable resources, and persistent storage. Seoul-based infrastructure may also reduce geographical network distance for applications serving Korean customers.
This deployment guide uses Ubuntu 24.04 LTS, Docker Compose, Python, PostgreSQL, Redis, and an Nginx reverse proxy.
Selecting a KVM Environment for Containerized Applications
Microservices require sufficient CPU capacity, memory, and storage to support multiple application processes simultaneously.
A VPS server from South Korea, OnliveServer, provides Seoul-based KVM virtualization, SSD storage, full root access, and configurations reaching 12 CPU cores and 48 GB RAM.
KVM provides an independent guest operating system, while Docker organizes application services within that environment. Containers generally share the guest Linux kernel, so their isolation differs from the boundary between separate virtual machines.
Resource allocation should reflect database activity, application concurrency, and caching requirements.
Installing Docker Engine and Compose
Update Ubuntu and install the packages needed to configure Docker’s official repository.
sudo apt update sudo apt install -y ca-certificates curl openssl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL \ https://download.docker.com/linux/ubuntu/gpg \ -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc
Add the 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” \ | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine and the Compose plugin:
sudo apt update sudo apt install -y docker-ce docker-ce-cli \ containerd.io docker-buildx-plugin \ docker-compose-plugin sudo systemctl enable –now docker
Verify the installation:
sudo docker version sudo docker compose version
Access to the Docker daemon carries significant administrative privileges. Restrict it to trusted accounts.
Creating the Application Directory
Maintain application files and container configurations within a dedicated project directory.
mkdir -p ~/microservices/api cd ~/microservices umask 077 printf ‘POSTGRES_PASSWORD=%s\n’ \ “$(openssl rand -hex 32)” > .env
The generated database password remains in a restricted environment file rather than appearing directly in the Compose configuration.
Do not commit the .env file to a public source-code repository.
Building the API Microservice
Create an api/requirements.txt file containing the required Python packages:
fastapi uvicorn psycopg[binary] redis
Create api/main.py:
import os import psycopg import redis from fastapi import FastAPI, HTTPException app = FastAPI() cache = redis.Redis( host=”redis”, port=6379, socket_connect_timeout=3, socket_timeout=3 ) @app.get(“/”) def home(): return {“service”: “API”, “status”: “running”} @app.get(“/health”) def health(): try: with psycopg.connect( host=”db”, dbname=”appdb”, user=”appuser”, password=os.environ[“DB_PASSWORD”], connect_timeout=3 ) as connection: connection.execute(“SELECT 1”) cache.ping() return {“status”: “healthy”} except Exception: raise HTTPException( status_code=503, detail=”Dependency unavailable” )
Create api/Dockerfile:
FROM python:3.12-slim WORKDIR /app COPY requirements.txt . RUN pip install –no-cache-dir \ -r requirements.txt RUN useradd –create-home –uid 10001 appuser COPY –chown=appuser:appuser main.py . USER appuser EXPOSE 8000 CMD [“uvicorn”, “main:app”, \ “–host”, “0.0.0.0”, “–port”, “8000”]
The API runs under a non-root container account. Its health endpoint checks PostgreSQL and Redis connectivity without exposing internal error details.
Configuring Docker Compose Services
Create compose.yaml in the project directory:
services: api: build: ./api restart: unless-stopped environment: DB_PASSWORD: ${POSTGRES_PASSWORD} ports: – “127.0.0.1:8000:8000” depends_on: db: condition: service_healthy redis: condition: service_healthy networks: – backend db: image: postgres:17 restart: unless-stopped environment: POSTGRES_DB: appdb POSTGRES_USER: appuser POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} volumes: – postgres_data:/var/lib/postgresql/data healthcheck: test: [“CMD”, “pg_isready”, “-U”, “appuser”, “-d”, “appdb”] interval: 10s timeout: 5s retries: 5 networks: – backend redis: image: redis:7-alpine restart: unless-stopped command: [“redis-server”, “–appendonly”, “yes”] volumes: – redis_data:/data healthcheck: test: [“CMD”, “redis-cli”, “ping”] interval: 10s timeout: 5s retries: 5 networks: – backend networks: backend: driver: bridge volumes: postgres_data: redis_data:
PostgreSQL and Redis communicate with the API through the Docker network. Neither database service publishes a public host port.
The API listens on the VPS loopback interface, allowing a host-based reverse proxy to forward authorized requests.
Starting and Monitoring the Containers
Validate the Compose configuration and deploy the services:
sudo docker compose config –quiet sudo docker compose up -d –build
Inspect container status and application logs:
sudo docker compose ps sudo docker compose logs –tail=50 api
Verify local API connectivity:
curl -fsS http://127.0.0.1:8000/health
A healthy deployment returns a successful response after both database dependencies become available.
Monitor CPU and memory consumption using:
sudo docker stats –no-stream
Setting Up an Nginx Reverse Proxy
Nginx provides a public entry point for the containerized API without exposing its application port directly.
Install Nginx and Certbot:
sudo apt install -y nginx certbot \ python3-certbot-nginx
Enter the registered application domain:
read -rp “Application domain: ” DOMAIN
The domain must already resolve to the VPS before requesting a TLS certificate.
Create the reverse proxy configuration:
sudo tee /etc/nginx/sites-available/microservices \ > /dev/null <<EOF server { listen 80; server_name $DOMAIN; location / { proxy_pass http://127.0.0.1:8000; 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; } location = /health { return 404; } } EOF
Enable and validate the configuration:
sudo ln -sfn \ /etc/nginx/sites-available/microservices \ /etc/nginx/sites-enabled/microservices sudo nginx -t sudo systemctl enable –now nginx sudo systemctl reload nginx
Apache can also provide reverse proxy functionality, but this deployment uses Nginx exclusively to avoid conflicting public network listeners.
Installing TLS Certificates
Configure HTTPS through Certbot:
sudo certbot –nginx -d “$DOMAIN” –redirect
Check certificate renewal:
sudo certbot renew –dry-run
Certificate issuance requires valid DNS records, appropriate network accessibility, and a correctly configured web server.
TLS protects data during transmission. Application authentication and authorization must still be implemented before exposing sensitive business operations.
Restricting Public Network Access
For a server using UFW, permit required administrative and web connections:
sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow OpenSSH sudo ufw allow ‘Nginx Full’ sudo ufw enable sudo ufw status verbose
Confirm the correct SSH port before enabling the firewall.
Docker’s published ports can bypass ordinary UFW filtering. Binding the API to the loopback interface and avoiding published database ports reduces unintended exposure.
Maintaining Persistent Container Volumes
Docker named volumes preserve database files independently of the normal container replacement lifecycle.
Inspect the available volumes:
sudo docker volume ls
Create a PostgreSQL database backup:
mkdir -p backups chmod 700 backups sudo docker compose exec -T db \ pg_dump -U appuser -d appdb -Fc \ > “backups/appdb-$(date +%F).dump”
Transfer backup archives to protected independent storage and test restoration regularly.
Avoid running docker compose down -v against production environments because it removes associated named volumes.
Persistent volumes preserve data during ordinary container replacement but do not protect against every server failure or accidental deletion.
Updating Production Microservices
Application updates should pass through development and staging environments before production deployment.
Rebuild updated application containers using:
sudo docker compose up -d –build api
Review application logs, dependency health, and database compatibility after deployment.
Pin tested package and container image versions for production releases. Configure resource limits, log rotation, and appropriate monitoring before introducing substantial customer traffic.
Virtualizor management, where available, can support server-level recovery operations, while Docker Compose manages individual application services.
A South Korea VPS provides a configurable foundation for containerized microservices. Reliable operation depends on controlled network exposure, maintained software images, persistent storage, encrypted connections, and tested recovery procedures.
