Docker compose 找不到 $PWD 环境变量 [英] Docker compose won't find $PWD environment variable

查看:66
本文介绍了Docker compose 找不到 $PWD 环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 docker-compose:

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/"

当我在 shell 中运行它时,在 docker-compose.yml 的目录中,我得到:

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.

并且撰写以 PWD 为空开始.

and the compose starts with PWD being empty.

我在文件中看不到任何错误,如下所示:https://docs.docker.com/compose/environment-variables/

I don't see any error in the file, as seen here: https://docs.docker.com/compose/environment-variables/

推荐答案

你不需要 ${PWD} 这个,你可以把路径设为相对路径,compose 会扩展它(一个compose 路径与 docker run 处理的路径之间的主要区别).

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/"

至于为什么compose看不到这个变量,那要看你的shell了.Compose 查找导出的环境变量、.env 文件的内容以及 docker-compose 命令的命令行标志.如果变量中的每一个都为空,您将收到该警告.

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.

这篇关于Docker compose 找不到 $PWD 环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆