Skip to main content
Back to Dev generators

Dev

Mock Docker Compose Generator

Every new project starts with the same docker-compose.yml boilerplate: service definitions, environment variables, volumes, health checks, and depends_on ordering. Writing this from scratch wastes time and introduces subtle bugs — wrong health check commands or a depends_on that doesn't wait for database readiness. A mock Docker Compose generator handles all of this automatically. The `database` input selects the database service: postgres uses postgres:15-alpine with pg_isready, mysql uses mysql:8.0 with mysqladmin ping, mongodb uses mongo:6-jammy with mongosh eval, and none omits it. The `includeCache` input adds a Redis cache service named 'cache' using redis:7-alpine. The `appPort` input sets the port mapping and injects PORT into the app environment. All services get restart: unless-stopped, named volumes, and healthcheck settings with correct commands per database.

Read the complete guide — 4 min read

How to use

  1. Choose your options above
  2. Click Generate
  3. Copy your result

Detailed instructions

  1. Select your database engine (PostgreSQL, MySQL, or MongoDB) from the Database dropdown.
  2. Set Include Redis Cache to yes if your app uses caching, or no to keep the output minimal.
  3. Enter the port number your application listens on in the App Port field (default is 3000).
  4. Click Generate to produce the docker-compose.yml output, then copy it with the copy button.
  5. Paste the file into your project root, replace placeholder passwords, and run `docker compose up -d`.

Use Cases

  • Bootstrapping a new Node.js or Python API with a Postgres database in under two minutes
  • Generating a reproducible dev environment YAML to commit alongside a new team member's onboarding docs
  • Creating a runnable docker-compose.yml for a tutorial or Hashnode blog post readers can clone and start immediately
  • Spinning up a throwaway MongoDB instance with Redis cache for a prototype without installing either natively
  • Replacing a conflicting local MySQL install with a containerized version on a custom port to avoid collisions

Tips

  • Change `POSTGRES_PASSWORD` to a variable reference like `${DB_PASSWORD}` and store the value in a `.env` file — it takes 30 seconds and keeps credentials out of version control.
  • If your app container exits immediately on first run, the database health check timeout may be too short; increase the `retries` value in the healthcheck block from 5 to 10.
  • Add a `profiles` key to the Redis service so it only starts when you explicitly run `docker compose --profile cache up`, keeping your default stack lighter during backend-only work.
  • Map a second port for your database service (e.g., `5432:5432`) so tools like TablePlus or DBeaver can connect directly without `docker exec`.
  • Use the generated file alongside a `Makefile` with targets like `make dev` and `make reset` — wrapping `docker compose up -d` and `docker compose down -v` makes onboarding one command.
  • For MongoDB, uncomment or add `MONGO_INITDB_DATABASE` to auto-create your app's database on first boot, saving the manual setup step.

FAQ

how do I run the generated docker-compose.yml file

Save the output as docker-compose.yml in your project root, then run docker compose up -d from that directory. The -d flag starts all services in the background. Use docker compose logs -f to tail logs, docker compose ps to check service health, and docker compose down to stop everything. Add -v to docker compose down if you also want to delete the named volumes and start fresh.

are the passwords in the generated file safe to commit to git

No — the defaults (devpassword, devuser) are placeholders for local development only. Before committing, replace hardcoded values with environment variable references like ${DB_PASSWORD} and store real secrets in a .env file added to .gitignore. Docker Compose reads a .env file from the project root automatically, so no extra tooling is needed.

what is the difference between the health checks for postgres mysql and mongodb

Each database requires its own readiness command. Postgres uses pg_isready -U devuser, MySQL uses mysqladmin ping -h localhost, and MongoDB uses mongosh --eval db.adminCommand('ping'). The generator applies the correct command for your chosen database so the depends_on condition in the app service actually waits for database readiness rather than just container start.

what happens if I set includeCache to yes but database to redis

The generator detects this and omits the separate cache service when database is already set to redis, avoiding a duplicate Redis container. The app service still receives a REDIS_URL environment variable pointing to the primary redis service on port 6379.

You might also like

Popular tools from other categories that share themes with this one.

Try these next

More free tools from other corners of the catalog, picked by shared themes.