title: How to pass an ARG to a Dockerfile in a docker-compose.yml
body: <p>I have a project <code>apkmirror-scraper-compose</code> with the following (simplified) structure:</p>
  
  <pre><code>.
  ├── docker-compose.yml
  └── tor
      └── Dockerfile
  </code></pre>
  
  <p>The <code>docker-compose.yml</code> is</p>
  
  <pre><code>version: '3'
  
  services: 
    tor:
      build:
        context: ./tor
        args:
          password: ""
      ports:
        - "9050:9050"
        - "9051:9051"
  </code></pre>
  
  <p>The <code>Dockerfile</code> in the <code>tor</code> directory is:</p>
  
  <pre><code>FROM alpine:latest
  EXPOSE 9050 9051
  ARG password
  RUN apk --update add tor
  RUN echo "ControlPort 9051" &gt;&gt; /etc/tor/torrc
  RUN echo "HashedControlPassword $(tor --quiet --hash-password $password)" &gt;&gt; /etc/tor/torrc
  CMD ["tor"]
  </code></pre>
  
  <p>I'm trying to pass the argument <code>password</code>, which as the value <code>""</code> (an emtpy string), to the <code>Dockerfile</code>, so that it can hash it with Tor and add a <code>HashedControlPassword</code> line to the configuration file (cf. <a href="https://www.torproject.org/docs/tor-manual.html.en" rel="nofollow noreferrer">https://www.torproject.org/docs/tor-manual.html.en</a>).</p>
  
  <p>However, if I <code>docker-compose build</code> followed by <code>docker-compose up</code>, the logs contain the following:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>In other words, the <code>password</code> argument is not getting 'picked up': Tor is saying it has "no value". Comparing with the example on <a href="https://docs.docker.com/compose/compose-file/#args" rel="nofollow noreferrer">https://docs.docker.com/compose/compose-file/#args</a>, however, I don't see what's wrong with either the <code>docker-compose.yml</code> or <code>Dockerfile</code>. </p>
  
  <p>Can anyone spot what the problem is?</p>