Fill in a form and get a clean, valid docker-compose.yml as you type. Start from a ready-made stack such as WordPress + MySQL or Node.js + PostgreSQL + Redis, then add services, ports, volumes, environment variables, dependencies and healthchecks.
Last updated:
Services
Advertisement
Advertisement
How to use the Docker Compose Generator
Pick a preset such as WordPress + MySQL and click Load preset, or start from the blank template.
Edit each service: set the image (or a build context), restart policy, ports, volumes and environment variables.
Wire services together with depends_on and choose whether to wait until a dependency is started or healthy.
Add healthchecks to databases and caches so dependent services start only when they are ready.
Fix any warnings shown under the YAML, such as a host port used twice or a missing image.
Copy or download docker-compose.yml and run docker compose up -d in the same folder.
Anatomy of a docker-compose.yml
A Compose file has one required section, services, and two optional ones that this generator fills in for you: volumes (named volumes used by any service) and networks (custom networks). Every service becomes one container on the same project network, and services reach each other by service name: a WordPress container connects to its database at db:3306, not localhost.
Key
What it does
Example
image
Image to pull and run; pin a tag for repeatable builds
postgres:16-alpine
build
Folder with a Dockerfile to build instead of pulling
.
ports
Publish a container port on the host as HOST:CONTAINER
"8080:80", "127.0.0.1:5432:5432"
volumes
Named volume or bind mount; add :ro for read-only
db_data:/var/lib/mysql
environment
Variables passed to the container; a key with no value is taken from your shell
TZ: UTC
env_file
Load variables from a file kept out of version control
.env
depends_on
Start order, optionally waiting for a healthy dependency
condition: service_healthy
restart
Restart policy: no, always, on-failure, unless-stopped
unless-stopped
healthcheck
Command Docker runs to decide if the container is healthy
test: ["CMD", "redis-cli", "ping"]
networks
Attach to custom networks to isolate tiers (frontend / backend)
- backend
Healthchecks that work for common images
A dependency marked healthy only helps if the target service actually has a healthcheck. These commands use tools that ship inside the official images:
Image
Test
Type
postgres
pg_isready -U postgres
CMD-SHELL
mysql
mysqladmin ping -h localhost
CMD
mariadb (10.4+)
healthcheck.sh --connect --innodb_initialized
CMD
redis
redis-cli ping
CMD
mongo (6+)
mongosh --quiet --eval "db.adminCommand('ping')"
CMD
Web app with curl installed
curl -f http://localhost:3000/health || exit 1
CMD-SHELL
Docker's defaults are a 30s interval, 30s timeout, 3 retries and no start period. Shorter intervals (5-10s) make docker compose up start dependent services sooner; a start period gives slow databases time to initialise without counting failures.
Everyday Compose commands
docker compose config validates the file and prints the fully resolved configuration.
docker compose up -d creates and starts everything in the background; docker compose ps shows status and health.
docker compose logs -f web follows the logs of one service.
docker compose down stops and removes containers and networks; add -v only if you also want to delete named volumes and their data.
docker compose pull && docker compose up -d updates to newer images of the tags you pinned.
Frequently asked questions
What is a docker-compose.yml file?
It is a YAML file that describes a multi-container application: which images to run, which ports to publish, which volumes and networks to create and how the containers depend on each other. Running docker compose up in the folder that contains it starts the whole stack with one command.
Do I still need the version line at the top?
No. The Compose Specification used by Docker Compose v2 ignores the top-level version key and prints a warning that it is obsolete. Leave it off unless an old tool still requires it; the generator can add version "3.8" if you tick the option.
What is the difference between a named volume and a bind mount?
A named volume such as db_data:/var/lib/mysql is managed by Docker and listed in the top-level volumes section, which is the best choice for database data. A bind mount such as ./src:/var/www/html maps a folder from your computer into the container, which is handy for source code and config files. The generator detects named volumes and declares them for you.
Why does depends_on not wait for my database to be ready?
With the short form, Compose only waits for the dependency container to start, not for the service inside it to accept connections. Give the database a healthcheck and set the condition to healthy (service_healthy); Compose then waits until the healthcheck passes before starting the dependent service.
What is the difference between CMD and CMD-SHELL in a healthcheck?
CMD runs the program directly with the arguments you give, for example ["CMD", "redis-cli", "ping"]. CMD-SHELL runs the whole string through the container's /bin/sh, so you can use pipes and || exit 1, for example ["CMD-SHELL", "pg_isready -U postgres"]. An exit code of 0 means healthy.
Why are the ports quoted in the output?
YAML 1.1 parsers can read unquoted values like 22:22 as a base-60 number, which breaks the port mapping. Quoting every HOST:CONTAINER pair as a string is the practice recommended in the Compose documentation, so the generator always quotes them.
Is it safe to put passwords in the file?
The presets use change-me placeholders so the stack works out of the box. For real deployments, move secrets into an env_file that is excluded from version control, or use Docker secrets, and never commit production passwords to a repository.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.