Compose does not see the $PWD variable in my volume path
- ${PWD}:/app mounts the wrong folder or nothingShort answer
Compose fills ${PWD} from the environment of the shell that runs it, not from the shell's own idea of the current folder. Where PWD is not set there, the value is blank. Use a relative path such as ./data, which Compose resolves from the compose file's folder, or set the variable yourself.
Fix it fast
1Find out which cause you have
Print the values Compose will use for interpolation and the resolved file. If PWD is missing or blank there, that is the whole problem.
docker compose config --environment | grep -i "^PWD" docker compose config2Match what you see, then jump to its fix
- 1
docker compose config shows an empty or broken volume source where ${PWD} was.PWD is not set in the environment Compose runs inFix - 2
The same blank substitution happens for any ${NAME} you use.You need a variable in the file but did not give it a value or defaultFix - 3
The path in compose.yaml is right, but the app inside the container sees no value.The variable is set in your shell but never reaches the containerFix
- 1
What does the error look like?
- ${PWD}:/app mounts the wrong folder or nothingCompose warns that a variable is not set and substitutes an empty string
Cause 1 of 3
PWD is not set in the environment Compose runs in
1Check
Compose uses Bash-like interpolation and reads the variables from the shell environment and a .env file. When a variable has no value and no default, it warns and uses an empty string.
docker compose config --environment2Fix
Stop depending on PWD. A relative host path starting with ./ is resolved from the compose file's directory, which is what you wanted.
services:
app:
volumes:
- ./src:/app/src3Verify
Resolve the file again and read the host path Compose printed.
docker compose config | grep -A3 volumesConfirmed by docs.docker.com
Cause 2 of 3
You need a variable in the file but did not give it a value or default
1Check
A name with no value is replaced by an empty string unless you add a default or a required marker.
docker compose config --no-interpolate | grep -n '\${'2Fix
Give it a default with ${NAME:-default}, or make a missing value stop the run with ${NAME:?message}. You can also put NAME=value in a .env file next to compose.yaml.
services:
app:
volumes:
- ${DATA_DIR:-./data}:/var/lib/app
- ${CONFIG_DIR:?CONFIG_DIR is not set}:/etc/app:ro3Verify
Run config once with and once without the variable set.
DATA_DIR=/srv/data CONFIG_DIR=/srv/conf docker compose config
docker compose configConfirmed by docs.docker.com
Cause 3 of 3
The variable is set in your shell but never reaches the container
1Check
Shell variables do not enter a container by themselves. They only work when you interpolate them in the file or list the name under environment.
docker compose run --rm app env | sort2Fix
Reference the variable in the environment section, either as a bare name or as NAME=${NAME}.
services:
app:
environment:
- DEBUG
- API_URL=${API_URL}3Verify
Run the same env listing again.
DEBUG=1 API_URL=http://example.com docker compose run --rm app env | grep -E 'DEBUG|API_URL'Confirmed by docs.docker.com
How do I stop it coming back?
- Use relative paths beginning with ./ for bind mounts in compose files.
- Give every ${VAR} a default or a required message, and keep the defaults in a committed .env.example.
- Run docker compose config in CI so an empty substitution fails the build.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix