When you have multiple containers — like one for your backend, one for your frontend, and one for your database — managing them all manually with docker run Commands can get messy. That’s where Docker Compose comes in.
Docker Compose lets you define and run multi-container applications using a simple YAML file, so your entire stack (frontend, backend, database, etc.) can be started with a single command.
In this guide, you’ll learn how to deploy a complete website or web app using Docker Compose, step by step.
See Also: How to Set Up a Complete CI/CD Pipeline with Jenkins (Automated Website Deployment Tutorial)
What Is Docker Compose?
Docker Compose is a tool that:
- Uses a
docker-compose.ymlfile to define how containers should run together. - Let's you manage multiple containers as one unified service.
- Simplifies networking, environment variables, and dependencies.
For example:
- Your frontend runs in one container.
- Your backend API runs in another.
- Your database (like PostgreSQL or MongoDB) runs in a third.
Docker Compose handles them all — linked, connected, and running in sync.
Step 1: Install Docker and Docker Compose
On most systems, Docker Desktop already includes Compose. To verify:
docker compose versionIf not installed, you can add it manually:
sudo apt update
sudo apt install docker-compose-pluginSee Also: How to Set Up Automated Website Deployment with GitHub Actions (Complete CI/CD Tutorial)
Step 2: Create a Project Structure
Example:
my-app/
├── frontend/
│ ├── Dockerfile
│ └── ...
├── backend/
│ ├── Dockerfile
│ └── ...
└── docker-compose.ymlEach folder contains its own Dockerfile describing how to build that container.
Step 3: Write a Docker Compose File
Here’s a simple docker-compose.yml example for a Node.js backend and a React frontend:
version: "3.9"
services:
backend:
build: ./backend
ports:
- "4000:4000"
environment:
- NODE_ENV=production
frontend:
build: ./frontend
ports:
- "3000:3000"
depends_on:
- backendHow it works:
- Each service (frontend/backend) is built from its respective folder.
depends_onensures the backend starts first.- Both containers share a private Docker network automatically.
See Also: How to Deploy a Website with Docker (Step-by-Step Tutorial)
Step 4: Build and Run the Containers
To start everything:
docker compose up --buildTo run in the background:
docker compose up -dVisit:
- Frontend → http://localhost:3000
- Backend → http://localhost:4000
Step 5: Managing the Stack
Stop all containers:
docker compose downRebuild after code changes:
docker compose up --build -dList active services:
docker compose psStep 6: Adding a Database (Example: PostgreSQL)
Extend the file to include a database service:
services:
backend:
build: ./backend
ports:
- "4000:4000"
environment:
- DATABASE_URL=postgres://user:pass@db:5432/mydb
depends_on:
- db
db:
image: postgres:14
restart: always
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: mydb
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:Now, your backend automatically connects to a PostgreSQL database.
Step 7: Deploying to a Server
- Install Docker + Compose on your VPS (DigitalOcean, AWS, etc.).
- Copy your project folder to the server via SCP or Git.
- Run:
docker compose up -d4. Use NGINX reverse proxy or Traefik to securely route public traffic to your containers.
Step 8: Add HTTPS
You can use Caddy, Traefik, or Certbot with Nginx to automatically issue SSL certificates for your containers.
Conclusion
Docker Compose makes containerized hosting simple and scalable. With a single YAML file, you can orchestrate your entire app — web, backend, and database — and deploy anywhere.
Next, in Hosting Academy, we’ll take the next leap: deploying containers with Kubernetes — the industry standard for scalable, cloud-native hosting.

