问题
Here's my docker-compose:
version: '2'
services:
couchpotato:
build:
context: ./couchpotato
dockerfile: Dockerfile
ports:
- 5050:5050
volumes:
- "${PWD}/couchpotato/data:/home/CouchPotato/data/"
- "${PWD}/couchpotato/config:/home/CouchPotato/config/"
When I run it inside the shell, in the directory of the docker-compose.yml, I get:
WARNING: The PWD variable is not set. Defaulting to a blank string.
and the compose starts with PWD being empty.
I don't see any error in the file, as seen here: https://docs.docker.com/compose/environment-variables/
回答1:
You don't need ${PWD}
for this, you can just make the path relative and compose will expand it (one major difference between compose paths and those processed by docker run
).
version: '2'
services:
couchpotato:
build:
context: ./couchpotato
dockerfile: Dockerfile
ports:
- 5050:5050
volumes:
- "./couchpotato/data:/home/CouchPotato/data/"
- "./couchpotato/config:/home/CouchPotato/config/"
As for why compose doesn't see this variable, that depends on your shell. Compose looks for an exported environment variable, contents of the .env file, and command line flags to the docker-compose command. If each of those comes up empty for the variable, you'll get that warning.
回答2:
I was with the same issues, on Windows.
For solve "mariadb keeping restarting", I was using this:
mariadb:
image: mariadb
volumes:
- ${PWD}/data:/var/lib/mysql
It solved, but always showed me the message:
WARNING: The PWD variable is not set. Defaulting to a blank string.
Then I just used on this way, whithout "." at beginning:
mariadb:
image: mariadb
volumes:
- /data:/var/lib/mysql
来源:https://stackoverflow.com/questions/41948232/docker-compose-wont-find-pwd-environment-variable