.env to Docker Compose Converter
Paste the contents of your .env file and get a Docker Compose service block generated from it. Variables are grouped into services with a simple comment directive, and the well-known keys such as IMAGE, PORT, VOLUME and CMD are mapped onto real Compose options instead of becoming stray environment entries.
.env content
docker-compose.yaml
Ready — paste some input or load the sample.
100% Client-Side · Privacy First. This tool runs entirely inside your browser. Nothing you type is uploaded, logged or sent to a server — you can even use it offline.
Overview
A .env file is the usual home for the configuration of a container, but a .env file on its own does not describe a container: it does not say which image to run, which port to publish or which volumes to mount. This converter turns an environment file into a compose file, using a small set of well known keys to describe the container and treating every other key as an environment variable of that service. The IMAGE key selects the image, PORT publishes a port, VOLUME mounts one or more paths, and CMD or COMMAND sets the command. Everything else is passed through into the environment block, with quoting that survives YAML. Services can be separated inside the same file with a comment such as # service: api, which lets you describe a multi-container stack in one paste. The result is a compose file you can start with docker compose up -d, and it is a fast way to turn a deployment script that writes an env file into something you can review and commit.
How to use the .env to docker compose converter
- 1Paste the contents of your .env file into the input panel.
- 2Add IMAGE, PORT, VOLUME or CMD keys if your file does not define them already.
- 3Split a multi-service file with a comment of the form "# service: api" on its own line.
- 4Read the notes panel, which lists the keys that were mapped onto Compose options.
- 5Run docker compose up -d and follow the result with docker compose logs.
- 6A variable that never reaches the container is the usual cause of a service that starts and then crashes, so compare the two lists.
Cheat sheet
The syntax you will use most, and what each part does.
| Pattern | What it means |
|---|---|
IMAGE=nginx:alpine |
Selects the image for the service, overriding the default image of the tool. |
PORT=8080 |
Publishes the port; a bare number is published on the same port on the host. |
VOLUME=./data:/app/data |
Mounts a path. Several volumes can be separated by commas. |
CMD=echo hello |
Sets the command the container runs, quoted so YAML keeps it as one string. |
# service: api |
Starts a new service block, so one paste can describe a whole stack. |
export FOO=bar |
The export prefix is accepted and stripped, since env files often come from a shell. |
Common mistakes
A value is cut off at the wrong place.
An unquoted value ends at a space followed by a hash, which is the standard comment rule in an env file. Quote the value if it contains spaces.
A secret ends up in the compose file.
The converter inlines every value, including passwords. Keep real secrets in a separate file and reference them with the env_file option in production.
The container cannot start.
Check the command. Many images expect a command but a few have their own entrypoint, and quoting mistakes in the CMD value are the usual cause.
Two services share one port.
Each service maps its own PORT, and two services on the same host port conflict. Give each one a distinct host port.
Worked examples
A single service
IMAGE=nginx:alpine PORT=8080
A compose file with one service, the image, the published port and the restart policy.
A stack with two services
# service: api IMAGE=api:1.0 PORT=3000 DATABASE_URL=postgres://db/app # service: db IMAGE=postgres:16 PORT=5432
A compose file with two services, each with its own image, port and environment.
Frequently asked questions
Are the values uploaded anywhere?
No. The file is parsed in your browser, so a .env that holds a database password never leaves the tab you opened it in.
Which keys control the container?
IMAGE becomes the image of the service, PORT becomes the published port, VOLUME becomes a bind mount, CMD becomes the command, and every other variable becomes an environment entry inside the container.
How do I handle a real secret?
Do not put the secret in the .env file that this tool reads. Keep the value in a secret manager or in a separate file that is not committed, and reference it from the generated Compose file with the env_file key.
Can it generate more than one service?
Yes. Start a new block with a comment that reads "# service: name" and the following variables belong to that service, so a whole stack comes out of a single .env file.
Why was one of my variables skipped?
The parser ignores blank lines and comment lines, and it treats a line that starts with export as a normal assignment. A value that contains an unquoted equals sign keeps everything after the first one.
What happens to a value with spaces?
It is quoted in the generated YAML, so a command such as CMD=echo hello world arrives as one string instead of three separate arguments.
Is the generated file complete?
It contains a services block with one service per group. Add a volumes block yourself when you use named volumes, because Compose needs to declare them separately from the mount.
Can I still use the same .env file for local development?
Yes, and you should. Compose reads a .env file in the project directory automatically, so the same variables can feed the local process and the container without duplicating them.
What happens to a variable that is not in the list of special keys?
It becomes an environment entry inside the container, which is exactly what an application expects when it reads the variable from its own environment.
How do I keep a password out of the generated file?
Leave the secret out of the input entirely and add an env_file entry to the service yourself, pointing at a file that is not committed to version control.
Can I use a different name for the service than the comment?
The comment sets the service name directly, so make it a valid Compose key with no spaces. Compose accepts letters, digits, dashes and underscores.