Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

shell - Docker compose won't find $PWD environment variable

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/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...