Free Web Developer Utility

Docker Compose Generator

Fast, production-grade Docker Compose for Node.js and PostgreSQL. Pick your services, configure environments, and download your compose file.

Quick Start Guide

How to use the compiler tool in 3 simple steps:

1. Select Stack

Select Web Proxies, Backend Languages, and Databases in the selector grid.

2. Configure Properties

Adjust container labels, network ports, and custom environment variables in tabs.

3. Copy & Deploy

Instantly copy or download the generated `docker-compose.yml` to run in your terminal.

Quick Stacks:

Select Services

Enable the components needed in your container network. We'll automatically wire up database dependencies and port configurations.

Web Proxy

Languages & Frameworks

Databases & Caching

NODE_ENV
production
PORT
3000

Live Network Flow

Web
Client
NODE

docker-compose.yml

# =========================================================================
# Generated dynamically by HYVO Docker Compose Builder (hyvo.in)
# =========================================================================

services:
  node:
    image: node:20-alpine
    container_name: node-app
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - PORT=3000

About the Docker Compose Generator Tool

Setting up a Node.js API with a PostgreSQL database is the cornerstone of modern web backends. This generator creates a secure local bridge between your Node container and a persistent Postgres database using volumes for data storage. Our free online Docker Compose builder resolves the configuration hurdles developers face when setting up multi-container networks locally. Manually writing YAML can lead to spelling errors, indentation crashes, and network connection issues. This tool automates the creation of a clean `docker-compose.yml` file, matching exposed host ports, linking dependencies via `depends_on`, setting restart limits, and configuring persistent named volumes for databases.

Production Node.js & PostgreSQL Dockerization Guide

Layer Caching for Fast npm Installs

When dockerizing Node.js, copy package.json and package-lock.json to the image first, then execute npm ci (clean install). This allows Docker to cache the node_modules layer, ensuring your builds are lightning-fast when only your source code changes.

Multi-Stage Build Optimization

A single-stage build carries npm caches and build-time dependencies, bloating your image size. Use a multi-stage Dockerfile to separate the dependency compiler phase from the runtime runner. Copy only production modules and source code into a clean alpine or slim node image.

Secure Non-Root Container Execution

Running your containers as the default root user poses security risks. The official node image includes a pre-configured, non-privileged system user named 'node'. Switch ownership of your directory and execute your entrypoint using USER node.

Production DockerfileOptimized
# Stage 1: Dependency Compiler
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production

# Stage 2: Minimal Runtime Runner
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY . .
USER node
EXPOSE 3000
CMD ["node", "server.js"]

What is Containerization?

Containerization is a lightweight form of virtualization that packages an application's code, dependencies, libraries, and configurations into a single executable package called a container. Unlike virtual machines (VMs) that require a full guest operating system, containers share the host OS kernel, making them incredibly fast to boot, memory-efficient, and portable across developer laptops, staging servers, and cloud clusters.

What is Docker?

Docker is the industry-standard software platform used to build, share, and run containerized applications. By utilizing a Dockerfile, you specify the exact steps to compile your app. Docker packages these instructions into a immutable "Docker Image." When you run that image, it becomes a "Docker Container." This ensures your application behaves exactly the same in local development as it does in production, eliminating the classic "works on my machine" problem.

What is Docker Compose?

If your application relies on more than one container (e.g., a frontend app, a backend API, a PostgreSQL database, and a Redis cache), running them manually using single `docker run` commands is tedious. You have to manually set up virtual networks, link ports, manage container dependencies, and map storage paths.

**Docker Compose** solves this by letting you define your entire multi-container application stack in a single YAML file (`docker-compose.yml`). With a simple command—`docker compose up`—Docker automatically spins up all the services, builds the virtual bridge networks, mounts storage volumes, and starts log streams.

Understanding Docker Compose settings

Exposed Ports

Mapped as `host:container` (e.g. `3000:3000`). The first port exposes the service to your host machine (localhost), while the second port is the internal port the app listens to inside the container.

Persistent Volumes

Named volumes (e.g. `postgres_data`) map directory paths inside the database container to the host storage. This ensures your database records, users, and tables are saved when you stop your container.

Service Networks

Docker Compose automatically sets up a shared bridge network. All services in the same file can reach each other using their container name (e.g., connection host becomes `postgres-db`).

How to Use the Generated File

1

Save the File

Download the file and save it exactly as `docker-compose.yml` in the root folder of your project.

2

Verify Docker Installation

Ensure you have Docker Desktop (Windows/macOS) or Docker Engine (Linux) installed and running on your machine.

3

Start your containers

Open your terminal in the directory of your file and run: `docker compose up` or `docker compose up -d` (to run in the background).

Frequently Asked Questions

How does Node.js connect to PostgreSQL in Docker?

By using the container name of the database service (e.g. 'postgres-db') as the hostname in your database connection string, like 'postgresql://postgres:postgres_password@postgres-db:5432/mydb'.

Are database changes saved when I stop the container?

Yes. We configure Docker named volumes (e.g. 'postgres_data') so your database records persist even when containers are stopped or removed.

What is a dynamic Docker network?

Docker Compose sets up a single network for your application by default. Each container joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

How do I verify container status?

Use the command `docker compose ps` to inspect running containers, mapped ports, and health statuses, or view them inside the graphical interface of Docker Desktop.

Build and scale with HYVO

Don't spend hours debugging Docker network links. Use this generator to wire your stack, and let our senior engineering collective build out your product.