Windows 10, docker for windows, simple webapp using nginx and ssl.

Simple thing when using VMs. I have three virtual machines. Every machine has static ip assigned by router. In hosts files I can map ips to host names so I'm able to comunicate between VMs using names: api1.mydev, api2.mydev, application.mydev. Of course all systems have access to other part of network parent. This simple thing took me few days in docker without any progress.

It was super simple to build docker images/containers and they work on custom ports, so localhost:443 works like a harm. I can't find way to:

  • use host name to connect to naginx@docker_container as container's ip changes with every sytem reboot.
  • assign host names to many containers as its impossible to define port in hosts file

I've tried nginx-proxy but it gives me 502 errors. I've found traefik but I'm not network guru and configuration looks overhelming for newbie.

The option i thought about is to put all services on one container and use nginx to resolve names but this method gives not true advantages over single VM machine and is against docker philosophy.

Is there is simpler way to achieve that? I have feeling that I've missed something in docker configuration.

  • Since you're running all containers in a single host, have you tried running your services using docker-compose? it allows you to connect containers in the same network to using the hostnames. docs.docker.com/compose
    – Oli
    Oct 2, 2021 at 11:31
  • @Oli yeah but you still won't be able to address each service by it's hostname in your browser :) You'll have to go through different port bindings per service, or just use traefik with example as I've stated in my answer
    – holms
    Oct 3, 2021 at 1:06
  • Did you manage to figure it out? I used to (with VMs) putting the VM's bridged mode non-localhost IP along with a dev.example.com or similar mapping into my hosts file. Similarly, onto my mobile device (with Adguard DNS user filter) while it's connected to home wifi, mapping it to an IP that is fixed to a running VM (even though it runs on a host, it has nothing to do with the hosts's IP). I don't like polluting "localhost" or referring to the random IP of the host from another device on the network. My VM has like how do I get this with Docker? Mar 18, 2022 at 14:24

1 Answer 1


I've been using traefik for this goal.

version: '3.7'


      image: traefik:latest
      container_name: traefik
      command: --api --docker --docker.domain=${DOMAIN:localhost} --logLevel=DEBUG
          - "80:80"
          - "8080:8080"
          - /var/run/docker.sock:/var/run/docker.sock
      restart: unless-stopped
          - "traefik.enable=true"
          - "traefik.backend=traefik"
          - "traefik.frontend.rule=Host:traefik.${DOMAIN:localhost}"
          - "traefik.port=8080"

    container_name: app-account
      - traefik
      - "traefik.backend=account"
      - "traefik.frontend.rule=Host:account.${DOMAIN:localhost}"
      - "traefik.frontend.headers.customRequestHeaders=Access-Control-Allow-Origin: *"

In here ${DOMAIN} is used only for overriding domain from shell if you'll use this compose file in production, let's say in Docker Swarm. If you'll use it locally only, then just replace ${DOMAIN:localhost} with localhost. Launching docker with this docker-compose file you can access this particular app-account app via account.localhost

  • Thanks for mentioning traefik đź‘Ť
    – Jono
    Jul 27, 2022 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.