Docker compose won't find $PWD environment variable

后端 未结 5 2280
星月不相逢
星月不相逢 2020-12-14 06:44

Here\'s my docker-compose:

version: \'2\'
services:
  couchpotato:
    build:
        context: ./couchpotato
        dockerfile: Dockerfile
    ports:
     -         


        
相关标签:
5条回答
  • 2020-12-14 07:08

    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.

    0 讨论(0)
  • 2020-12-14 07:14

    My advice: change all $PWD to .

    0 讨论(0)
  • 2020-12-14 07:19

    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
    
    0 讨论(0)
  • 2020-12-14 07:21

    I had the same issue with one of my env vars. On looking at my bashrc file more closely, I found out that I hadn't exported that variable.
    Before:
    VAR=<value>
    After:
    export VAR=<value>

    0 讨论(0)
  • 2020-12-14 07:23

    $PWD will not work if you are running using sudo. Try the recommended settings from Docker for Linux https://docs.docker.com/engine/install/linux-postinstall/.

    Sudo will run as a different user, with a different env.

    $ sudo env | grep -i pwd
    $ env | grep -i pwd
    PWD=/home/user
    OLDPWD=/
    
    0 讨论(0)
提交回复
热议问题