Docker compose won't find $PWD environment variable

我的梦境 提交于 2019-12-30 03:47:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!