title: Reach host with Docker Compose
body: <p>I have a Docker Compose v2 file which starts a container. I locally run a service on port 3001. I want to reach this service from the Docker container.</p>
  
  <p>The Docker Compose file looks like this:</p>
  
  <pre><code>version: '2'
  services:
    my-thingy:
      image: my-image:latest
      #network_mode: host #DOES not help
      environment:
        - THE_HOST_I_WANT_TO_CONNECT_TO=http://127.0.0.1:3001
      ports:
    - "3010:3010"
  </code></pre>
  
  <p>Now, how can I reach <code>THE_HOST_I_WANT_TO_CONNECT_TO</code>? </p>
  
  <p>What I tried is:</p>
  
  <ul>
  <li>Setting <code>network_mode</code> to host. This did not work. 127.0.0.1 could not be reached.</li>
  <li>I can also see that I can reach the host from the container if I use the local IP of the host. A quick hack would be to use something like <code>ifconfig | grep broadcast | awk '{print $2}'</code> to obtain the IP and substitute that in Docker Compose. Since this IP can change on reconnect and different setups can have different <code>ifconfig</code> results, I am looking for a better solution.</li>
  </ul>