title: docker-compose how to define container scoped network like in docker run?
body: <p>Running 2 containers where <code>mycontainer2</code> must use the same network stack of <code>mycontainer1</code>. As if the two containers were running in the same machine. Here how I try to do by using <code>docker run</code> with <a href="https://docs.docker.com/engine/reference/run/#network-settings" rel="nofollow noreferrer">--network container:xxx</a></p>
  <pre><code>$ docker run -it --rm --name mycontainer1 -p 6666:7777 myregistry/my-container1:latest
  
  $ docker run -it --rm --network container:mycontainer1 --name mycontainer2 myregistry/my-container2:latest
  </code></pre>
  <p>I tried to replicate this behavior using <code>docker-compose</code> instead. But the <a href="https://docs.docker.com/compose/compose-file/#networks" rel="nofollow noreferrer">networks: definition</a> of <code>docker-compose.yaml</code> doesn't indicate something equivalent to the <code>--network container:xxx</code> option of <code>docker run</code>. Is it possible in <code>docker-compose</code> to configure two containers to use the same network stack?</p>