CraftedTemplate
Blog How to Deploy Containerized Apps with Docker Compose (Step-by-Step Guide)

How to Deploy Containerized Apps with Docker Compose (Step-by-Step Guide)

11/1/2025 • Festus Ayomike
How to Deploy Containerized Apps with Docker Compose (Step-by-Step Guide)

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.yml file 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:

Code · batchfile
docker compose version

If not installed, you can add it manually:

Code · batchfile
sudo apt update
sudo apt install docker-compose-plugin

See Also: How to Set Up Automated Website Deployment with GitHub Actions (Complete CI/CD Tutorial)

Step 2: Create a Project Structure

Example:

Code · batchfile
my-app/
├── frontend/
│   ├── Dockerfile
│   └── ...
├── backend/
│   ├── Dockerfile
│   └── ...
└── docker-compose.yml

Each 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:

Code · yaml
version: "3.9"

services:
  backend:
    build: ./backend
    ports:
      - "4000:4000"
    environment:
      - NODE_ENV=production

  frontend:
    build: ./frontend
    ports:
      - "3000:3000"
    depends_on:
      - backend

How it works:

  • Each service (frontend/backend) is built from its respective folder.
  • depends_on ensures 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:

Code · batchfile
docker compose up --build

To run in the background:

Code · batchfile
docker compose up -d

Visit:

  • Frontend → http://localhost:3000
  • Backend → http://localhost:4000

Step 5: Managing the Stack

Stop all containers:

Code · batchfile
docker compose down

Rebuild after code changes:

Code · batchfile
docker compose up --build -d

List active services:

Code · batchfile
docker compose ps

Step 6: Adding a Database (Example: PostgreSQL)

Extend the file to include a database service:

Code · yaml
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

  1. Install Docker + Compose on your VPS (DigitalOcean, AWS, etc.).
  2. Copy your project folder to the server via SCP or Git.
  3. Run:
Code · batchfile
docker compose up -d

4. 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.