Docker and Compose
Use getmyenv with Docker and Docker Compose: wrap docker compose with npx getmyenv run, or write a .env with export for env_file and bind mounts.
Last updated: 2026-09-28
How values reach a container
${VAR}in the compose file, filled in when you rundocker compose.- A bare
environment: - VARentry, copied from the shell that runsdocker compose. env_file:, read from a file.- A
.envfile mounted into the container. docker run -e VAR, copied from the shell.
Wrap the command with run
For ${VAR}, bare environment: entries and docker run -e VAR, wrap the command. Values from run win over --env-file and the project .env for interpolation.
npx getmyenv run production -- docker compose up -d
npx getmyenv run -- docker run -e DATABASE_URL my-imageWrite a file with export
env_file: and a mounted .env read a real file. Write it with export, then run your usual command. The file is plaintext and stays on disk until you delete it.
npx getmyenv export -c production -o ./.env --yes
docker compose up -dWhat to know
- After
up -d, Docker keeps the values in the container config.docker inspectshows them. docker restartkeeps them. Recreating the containers needsrunorexportagain.- Keep
.envout of images: list it in.dockerignore, and neverCOPY .env.
Read-only contexts on servers
On a server, set GETMYENV_TOKEN to a server token for the Read-only context. run and export then work from an allowlisted IP, on a trusted or approved machine. Details in /docs/machine-access.