Docker Compose for Web Developers: Managing Containerized Apps

Verified Knowledge
Containerization: Docker packages your application code, its Node/PHP version, and all Linux dependencies into a single portable image. Docker Compose coordinates multiple images (like your App, your Database, and Redis) from a single YAML file.
The "Works on My Machine" Problem
You build an application on a Macbook running Node.js 20. Your client's server is running Ubuntu 18.04 with Node.js 14. You deploy the app, and the server crashes with a syntax error.
This is the exact problem Docker was invented to solve.
Why Use Docker Compose?
A typical full-stack Next.js app needs:
- The Next.js frontend container.
- A PostgreSQL database container.
- A Redis caching container.
Instead of running three separate docker run commands in the terminal, Docker Compose allows you to define the relationship between these containers in a docker-compose.yml file.
Step 1: Install Docker on your VPS
If you've just spun up a fresh AmanaFlow Cloud Server:
sudo apt update
sudo apt install docker.io docker-compose -y
sudo systemctl enable docker
sudo systemctl start docker
Step 2: The docker-compose.yml File
Create a new file in your project directory:
version: '3.8'
services:
web:
image: node:20-alpine
working_dir: /app
volumes:
- .:/app
ports:
- "3000:3000"
command: npm run dev
depends_on:
- db
- redis
db:
image: postgres:15-alpine
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: strongpassword123
POSTGRES_DB: myapp
volumes:
- pgdata:/var/lib/postgresql/data
redis:
image: redis:alpine
volumes:
pgdata:
Step 3: Magic Execution
Instead of installing PostgreSQL or Redis manually on your server, simply type:
docker-compose up -d
Docker will pull the official database images, spin up your Node application, network them together automatically, and map port 3000 to the public web.
The Ultimate Container Host
Deploy your Docker swarms on AmanaFlow's unmanaged Cloud Servers. Featuring AMD EPYC processors for insane compilation speeds.
Post-Deployment: Persistent Volumes
The most critical part of the YAML file is the volumes: block at the bottom.
By default, when a Docker container is destroyed, all data inside it burns with it. By declaring a named volume (pgdata), the PostgreSQL data is safely mapped to the host VPS's hard drive, persisting across restarts and deployments.
FAQs
Q: Can I run cPanel inside Docker?
A: Technically yes, but practically no. Traditional monolithic panels like cPanel expect deep, uncontrolled root access to the OS kernel. Use CyberPanel or CloudPanel if you want modern stack management.
More from Developer Tutorials
View Category
How to Force HTTPS Redirects Using .htaccess in WordPress
You installed an SSL, but users are still landing on the insecure HTTP version. Here are the exact codes to force rigid HTTPS routing.

How to Install WordPress with LEMP Stack on Ubuntu 24.04
A complete step-by-step guide to installing the high-performance LEMP stack (Linux, Nginx, MariaDB, PHP) and WordPress on an unmanaged Ubuntu VPS.

Deploying production-ready Node.js Apps with PM2 and Nginx
Don't run 'npm start' and close your terminal. Learn how to keep your Next.js and Express APIs online forever using PM2 process management.