如何将ARG传递给docker-compose.yml中的Dockerfile

时间:2017-05-02 08:15:05

标签: docker docker-compose

我有一个项目apkmirror-scraper-compose,其中包含以下(简化)结构:

.
├── docker-compose.yml
└── tor
    └── Dockerfile

docker-compose.yml

version: '3'

services: 
  tor:
    build:
      context: ./tor
      args:
        password: ""
    ports:
      - "9050:9050"
      - "9051:9051"

Dockerfile目录中的tor是:

FROM alpine:latest
EXPOSE 9050 9051
ARG password
RUN apk --update add tor
RUN echo "ControlPort 9051" >> /etc/tor/torrc
RUN echo "HashedControlPassword $(tor --quiet --hash-password $password)" >> /etc/tor/torrc
CMD ["tor"]

我正在尝试将参数password作为值""(一个emtpy字符串)传递给Dockerfile,以便它可以使用Tor对其进行哈希并添加配置文件的HashedControlPassword行(参见https://www.torproject.org/docs/tor-manual.html.en)。

但是,如果我docker-compose build后跟docker-compose up,则日志包含以下内容:

Creating network "apkmirrorscrapercompose_default" with the default driver
Starting apkmirrorscrapercompose_tor_1
Attaching to apkmirrorscrapercompose_tor_1
tor_1  | May 02 08:03:59.344 [notice] Tor v0.2.8.12 running on Linux with Libevent 2.0.22-stable, OpenSSL LibreSSL 2.4.4 and Zlib 1.2.8.
tor_1  | May 02 08:03:59.345 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
tor_1  | May 02 08:03:59.345 [notice] Read configuration file "/etc/tor/torrc".
tor_1  | May 02 08:03:59.349 [warn] Linelist option 'HashedControlPassword' has no value. Skipping.
tor_1  | May 02 08:03:59.349 [warn] ControlPort is open, but no authentication method has been configured.  This means that any program on your computer can reconfigure your Tor.  That's bad!  You should upgrade your Tor controller as soon as possible.

换句话说,password参数没有得到“拾取”:Tor说它“没有价值”。但是,与https://docs.docker.com/compose/compose-file/#args上的示例相比,我看不出docker-compose.ymlDockerfile有什么问题。

有人能发现问题所在吗?

1 个答案:

答案 0 :(得分:0)

我认为问题在于password是一个空字符串。如果我将其替换为"foo",则docker-compose up似乎按预期工作。