AmanaFlow.
Developer Tutorials

Docker Compose for Web Developers: Managing Containerized Apps

Docker Compose for Web Developers: Managing Containerized Apps

Verified Knowledge

AF
AmanaFlow Engineering
L3 Systems Team
3 min read
TL;DR

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:

  1. The Next.js frontend container.
  2. A PostgreSQL database container.
  3. 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.

View Cloud Servers

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.

Share this post
Last updated March 2026