title: docker-compose - using localhost inside and outside of contaniner aspnet core
body: <p>I have 2 serviceA and serviceB that I use from my pc at</p>
  
  <ul>
  <li><a href="https://localhost:5001/servicea" rel="nofollow noreferrer">https://localhost:5001/servicea</a> </li>
  <li><a href="https://localhost:5002/serviceb" rel="nofollow noreferrer">https://localhost:5002/serviceb</a></li>
  </ul>
  
  <p>The services could also call each other.</p>
  
  <p>Now I would like to use docker-compose</p>
  
  <pre><code>version: '2.4'
  
  services:
    servicea:
      image: ${DOCKER_REGISTRY-}servicea
      ports:
       - "5001:5001"
      environment:
       - ASPNETCORE_URLS=https://host.docker.internal:5001
      build:
        network: host
        context: .
        dockerfile: Service1/Dockerfile
  
    serviceb:
      image: ${DOCKER_REGISTRY-}serviceb
      ports:
       - "5002:5002"
      environment:
       - ASPNETCORE_URLS=https://host.docker.internal:5002
      build:
        network: host
        context: .
        dockerfile: Service2/Dockerfile
  </code></pre>
  
  <p>The services are accessible from my pc via localhost, but not from inside of one container to another </p>
  
  <p>If I log into serviceA container:</p>
  
  <ul>
  <li><code>curl --insecure https://host.docker.internal:5002/serviceB</code> - working</li>
  <li><code>curl --insecure https://127.0.0.1:5002/serviceB</code> - not working</li>
  <li><code>curl --insecure https://localhost:5002/serviceB</code> - not working (this is what I need)</li>
  </ul>
  
  <p>I have a default dotnet core 3.1 api, using linux containers running in wsl2 with the following default dockerfile</p>
  
  <pre><code>FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
  WORKDIR /app
  EXPOSE 5001
  ...
  </code></pre>
  
  <p>Question: How can I (inside a container) access other containers using localhost, and still be able to access the containers from my pc using localhost (outside docker)?</p>
  
  <p>I've tried various combination of setting the ASPNETCORE_URLS and using v3.4 with network_mode: host with no luck. </p>
  
  <p>Thanks for any help!</p>