In Docker-compose, don't see the host names of other services

I’m trying to write an application which uses Privoxy and Tor as separate services in a Docker multi-container application. The directory, called apkmirror-scraper-compose, has the following structure:

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

where the docker-compose.yml is

  • Amazon ECS error: cannot create a task definition with no containers
  • PyMongo - UserNotFound: Could not find user authenticated@admin
  • anyway to setup npm credentials over `npm login` without reading input from STDIN?
  • `Authorization Token has expired` issue AWS-CLI on MacOS Sierra
  • entrypoint file not found
  • DigitalOcean: How to run Docker command on newly created Droplet via Java API
  • version: '3'
    
    services:
      privoxy:
        build: ./privoxy
        links:
          - tor
    
      tor:
        build:
          context: ./tor
          args:
            password: "foo"
    
      scraper:
        build: ./scraper
        links:
          - tor
          - privoxy
    

    where the Dockerfile in the tor directory is

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

    and that in privoxy is

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

    Finally, the Dockerfile for scraper is

    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
    

    where run.sh contains the single line

    until nc -z tor 9050; do echo "Waiting for tor..." && sleep 1; done;
    

    Basically, with the nc -z command, I’m waiting for the destination tor at port number 9050 to be listening. However, if I run docker-compose build followed by docker-compose up, I see the following:

    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...
    

    where Waiting for tor... goes on indefinitely.

    As I understand from https://docs.docker.com/compose/compose-file/#links, the “containers for the linked service will be reachable at a hostname identical to the alias, or the service name if no alias was specified”. Since I have not specified an alias, the hostname should be tor, right? Can someone explain why this is not working?

  • Saving files on Mac OSX host to Docker container (auto-reloading)
  • Running a Java war file deployed on Tomcat over Windows server 2016 Docker container
  • How to disable Nginx caching when running Nginx using Docker
  • Conncetion to docker daemon on remote host
  • How do debug multiple dot.net core services in containers from Visual Studio Mac
  • Boot2docker VM graphics
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.