Free tool · Developer tools
Docker Compose generator
Fill in a form for each service and get a compose.yaml file next to it. The starting example has three services, 1 published port and 1 named volume, and comes to 30 lines of YAML.
- Free
- No sign-up
- Runs in your browser
- 3 services
- 1 published port
- 1 named volume
- 30 lines
name: shop
services:
web:
image: example/web:1.4
restart: unless-stopped
ports:
- "8080:80"
environment:
- API_URL=http://api:3000
volumes:
- ./static:/srv/static:ro
depends_on:
- api
api:
image: example/api:1.4
restart: unless-stopped
environment:
- LOG_LEVEL=info
- DB_HOST=db
depends_on:
- db
db:
image: example/db:1.4
restart: always
environment:
- DB_NAME=shop
volumes:
- dbdata:/var/lib/data
volumes:
dbdata:
| Service | Image | Ports | Depends on |
|---|---|---|---|
| web | example/web:1.4 | 8080:80 | api |
| api | example/api:1.4 | none | db |
| db | example/db:1.4 | none | none |
How to use the Docker Compose Generator
- Type an optional Project name. It becomes the top-level name line.
- For each service fill in Service name and Image, then Ports, Environment, Volumes, Restart policy, Depends on and an optional Command.
- Press Add a service for another block, or Remove this service to drop one.
- Read the YAML and the table of services, then press Copy YAML or Download compose.yaml.
How do I write a docker compose file?
A Compose file describes an application as a set of services. Each service has a name and an image, and the rest is optional. Under services, every name gets its own block with keys such as ports, environment, volumes, restart and depends_on. The official documentation prefers the file name compose.yaml, and the page offers that name when you download. Older names such as docker-compose.yml are still read.
The starting example shows the shape. A web service publishes port 8080 and waits for api, api waits for db, and db keeps its data in a named volume called dbdata. The generator wrote the services in the order you entered them, and added the top-level volumes section on its own because dbdata is a name and not a path.
What does each field turn into?
Ports use the short form HOST:CONTAINER, so 8080:80 sends port 8080 on your machine to port 80 in the container. An address in front, as in 127.0.0.1:5000:5000/tcp, limits the port to that address, and a /udp or /tcp suffix picks the protocol. Port numbers must be from 1 to 65535. Environment lines are written NAME=value, one per line, and added in list form. Volume lines are source:/path in the container, with :ro for read only.
A source that starts with a dot, a slash or a tilde is a folder on your machine. Any other source is a named volume, and the generator lists it under the top-level volumes key once, however many services use it. The table shows the YAML for each kind of line.
| You type | YAML written |
|---|---|
| Ports: 8080:80 | ports: - "8080:80" |
| Ports: 127.0.0.1:5000:5000/tcp | ports: - "127.0.0.1:5000:5000/tcp" |
| Environment: MODE=prod | environment: - MODE=prod |
| Environment: GREETING=hello world | environment: - "GREETING=hello world" |
| Volumes: ./data:/data:ro | volumes: - ./data:/data:ro |
| Volumes: cache:/cache | volumes: - cache:/cache volumes: cache: |
| Restart policy: no | restart: "no" |
How do restart and depends_on work?
The documented restart values are no, always, on-failure and unless-stopped, and no is the default, which is why the first choice in the list leaves the line out. The generator writes no in quotes, because an unquoted no can be read by a YAML parser as the boolean false.
The short form of depends_on is a plain list of service names. Waiting for a health check needs the long form with a condition such as service_healthy, which this page does not write. The generator checks that every name in Depends on is one of your services and rejects a service that depends on itself. The env file generator helps when the environment values grow long, and the gitignore generator keeps the secrets out of the repository.
How is the file checked?
Names are limited to lowercase letters, digits, hyphens and the _ sign, ports and volumes must match their short forms, and an error names the service and shows what to write. Quoting follows fixed rules: words that could be read as a number or a boolean are put in double quotes, and that includes service names such as no or 123 and the names under Depends on. A value that ends in a colon is quoted too. Compose treats a dollar sign in a value as the start of a variable, so the generator writes each literal one as two dollar signs, and you need to type a single one only. Volume sources may not contain spaces, and two services that depend on each other in a circle are refused with the circle spelled out. Ports take the forms 8080:80, 127.0.0.1:8080:80 and a plain container port; IPv6 addresses and an empty host port are not supported here. The page does not talk to any server and cannot confirm that an image exists, so let Compose validate the downloaded file before you rely on it. The old top-level version line is obsolete and the generator leaves it out.
Everything runs in the page while you type, and nothing is uploaded.
Use it with
- Cron Expression Generator: build and explain cron schedules.
- .gitignore Generator: gitignore generator: tick your languages, systems and editors, add your own patterns, then copy or download a clean .gitignore file in one step.
- Apache VirtualHost Generator: apache VirtualHost generator: enter a domain and folder, choose HTTPS, www and logs, and copy a ready VirtualHost block for Apache 2.4.
Questions
What should a docker compose file be called?
The official documentation names compose.yaml as the preferred file name, with compose.yml also accepted. The older docker-compose.yml and docker-compose.yaml still work.
Do I still need the version line?
No. The documentation calls the top-level version property obsolete, and Compose warns if it is present. This generator leaves it out.
How do I map a port in a compose file?
Write HOST:CONTAINER under ports, for example 8080:80. The generator puts each mapping in double quotes and accepts an address prefix and a /tcp or /udp suffix.
How do I add a named volume?
Type the volume as name:/path/in/container under Volumes. A source that is not a path is listed under the top-level volumes key automatically.
Does depends_on wait until the database is ready?
No. The short form only starts the listed services first and does not wait for them to be ready. To wait for a healthy service, use the long form with condition: service_healthy, which this page does not write.
Which restart values can I use?
The documentation lists no, always, on-failure and unless-stopped. The generator offers those four, or leaves the line out so the default of no applies.
Sources
The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.