在Docker-compose中,看不到其他服务的主机名

时间:2017-05-02 11:46:24

标签: docker docker-compose netcat

我正在尝试编写一个使用Privoxy和Tor作为Docker多容器应用程序中的单独服务的应用程序。名为apkmirror-scraper-compose的目录具有以下结构:

.
├── docker-compose.yml
├── privoxy
│   ├── config
│   └── Dockerfile
├── scraper
│   ├── Dockerfile
│   ├── newnym.py
│   ├── requirements.txt
│   └── run.sh
└── tor
    └── Dockerfile

docker-compose.yml

version: '3'

services:
  privoxy:
    build: ./privoxy
    links:
      - tor

  tor:
    build:
      context: ./tor
      args:
        password: "foo"

  scraper:
    build: ./scraper
    links:
      - tor
      - privoxy

Dockerfile目录中的tor

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

privoxy中的

FROM alpine:latest
EXPOSE 8118
RUN apk --update add privoxy
COPY config /etc/privoxy/config
CMD ["privoxy", "--no-daemon", "/etc/privoxy/config"]

最后,Dockerfile的{​​{1}}是

scraper

其中FROM python:2.7-alpine ADD . /scraper WORKDIR /scraper COPY run.sh /scraper/run.sh RUN chmod +x /scraper/run.sh ENTRYPOINT /scraper/run.sh 包含单行

run.sh

基本上,使用until nc -z tor 9050; do echo "Waiting for tor..." && sleep 1; done; 命令,我正在等待端口号nc -z的目标tor正在侦听。但是,如果我运行9050后跟docker-compose build,我会看到以下内容:

docker-compose up

Starting apkmirrorscrapercompose_tor_1 Starting apkmirrorscrapercompose_privoxy_1 Creating apkmirrorscrapercompose_scraper_1 Attaching to apkmirrorscrapercompose_tor_1, apkmirrorscrapercompose_privoxy_1, apkmirrorscrapercompose_scraper_1 tor_1 | May 02 15:10:02.757 [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 15:10:02.757 [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 15:10:02.757 [notice] Read configuration file "/etc/tor/torrc". privoxy_1 | 2017-05-02 15:10:03.250 7fb755a28b48 Info: Privoxy version 3.0.24 privoxy_1 | 2017-05-02 15:10:03.250 7fb755a28b48 Info: Program name: privoxy tor_1 | May 02 15:10:02.781 [notice] Opening Socks listener on 127.0.0.1:9050 tor_1 | May 02 15:10:02.781 [notice] Opening Control listener on 127.0.0.1:9051 tor_1 | May 02 15:10:02.000 [notice] Parsing GEOIP IPv4 file /usr/share/tor/geoip. scraper_1 | Waiting for tor... tor_1 | May 02 15:10:03.000 [notice] Parsing GEOIP IPv6 file /usr/share/tor/geoip6. tor_1 | May 02 15:10:03.000 [warn] You are running Tor as root. You don't need to, and you probably shouldn't. tor_1 | May 02 15:10:03.000 [notice] We were built to run on a 64-bit CPU, with OpenSSL 1.0.1 or later, but with a version of OpenSSL that apparently lacks accelerated support for the NIST P-224 and P-256 groups. Building openssl with such support (using the enable-ec_nistp_64_gcc_128 option when configuring it) would make ECDH much faster. tor_1 | May 02 15:10:03.000 [notice] Bootstrapped 0%: Starting tor_1 | May 02 15:10:03.000 [notice] Bootstrapped 80%: Connecting to the Tor network tor_1 | May 02 15:10:04.000 [notice] Bootstrapped 85%: Finishing handshake with first hop tor_1 | May 02 15:10:04.000 [notice] Bootstrapped 90%: Establishing a Tor circuit tor_1 | May 02 15:10:04.000 [notice] Tor has successfully opened a circuit. Looks like client functionality is working. tor_1 | May 02 15:10:04.000 [notice] Bootstrapped 100%: Done scraper_1 | Waiting for tor... scraper_1 | Waiting for tor... scraper_1 | Waiting for tor... scraper_1 | Waiting for tor... scraper_1 | Waiting for tor... scraper_1 | Waiting for tor... 无限期地继续。

据我所知https://docs.docker.com/compose/compose-file/#links,“链接服务的容器可以在与别名相同的主机名上访问,如果没有指定别名,则可以访问服务名称”。由于我没有指定别名,因此主机名应为Waiting for tor...,对吧?有人可以解释为什么这不起作用吗?

0 个答案:

没有答案