title: What is the equivalent of --add-host=host.docker.internal:host-gateway in a Compose file
body: <p>Starting from Docker version <code>20.10</code> (<a href="https://github.com/moby/moby/pull/40007" rel="noreferrer">https://github.com/moby/moby/pull/40007</a>), there is a new special string <code>host-gateway</code> that one can use within the <code>--add-host</code> run flag to allow a direct connection from inside a docker container to the local machine on Linux based systems. And this is very nice.</p>
  <p>But what is the equivalent of <code>--add-host=host.docker.internal:host-gateway</code> in a Compose file?</p>
  <p>e.g. in:</p>
  <pre class="lang-sh prettyprint-override"><code>$ docker run \
    --rm \
    --name postgres \
    -p &quot;5433:5432&quot; \
    -e POSTGRES_PASSWORD=**** \
    --add-host=host.docker.internal:host-gateway \
    -d postgres:14.1-bullseye
  </code></pre>
  <p>How would the same <code>--add-host</code> flag fit in this Docker Compose equivalent template:</p>
  <pre class="lang-yaml prettyprint-override"><code>version: '3.9'
  
  services:
    postgres:
      image: postgres:14.1-bullseye
      environment:
        POSTGRES_PASSWORD: ****
      ports:
        - &quot;5433:5432&quot;
  </code></pre>
  <p>It's for sure not: <code>network_mode: host</code> at the service level (see <a href="https://github.com/compose-spec/compose-spec/blob/master/spec.md#network_mode" rel="noreferrer">#Doc</a>).</p>