Docker for windows: how to access container from dev machine (by ip/dns name)

Questions like seem to be asked but I really don’t get it at all.

I have a window 10 dev machine host with docker for windows installed. Besides others networks it has DockerNAT netwrok with IP 10.0.75.1

  • Docker rancher/agent won't start
  • Bash script fails to run node on docker image
  • how to install libcontainer docker in place of lxc-docker
  • Cannot connect to the daemon docker in a docker image of docker
  • RHEL7: How to solve “ import read failed(2)”?
  • How do I set the AWS Autoscaler to use the same IP addresses?
  • I run some containers with docker-compose:

    version: '2'
    services:
        service_a:
            build: .
            container_name: docker_a
    

    It created some network bla_default, container has IP 172.18.0.4, ofcource I can not connect to 172.18.0.4 from host – it doesn’t have any netwrok interface for this.

    What should I do to be able to access this container from HOST machine? (by IP) and if possible by some DNS name? What should I add to my docker-compose.yml, how to configure netwroks?

    For me it should be something basic, but I really don’t understand how all this stuff works and to access to container from host directly.

  • ansible playbook: setup and connect to docker (authentication or permission failure)
  • docker-compose up "ERROR: Error processing tar file(archive/tar: invalid tar header)
  • Cannot access files inside Vagrant Sync Folder
  • Accessing Docker containers and KVM VMs through VPN
  • Docker compose v2 containers not finding each other (though v1 does)
  • Service Fabric Cluster with Docker Containers with windowsservercore and iis server
  • 2 Solutions collect form web for “Docker for windows: how to access container from dev machine (by ip/dns name)”

    The easiest option is port mapping: https://docs.docker.com/compose/compose-file/#/ports

    just add

    ports:
        - "8080:80"
    

    to the service definition in compose. If your service listens on port 80, requests to localhost:8080 on your host will be forwarded to the container. (I’m using docker machine, so my docker host is another IP, but I think localhost is how docker for windows appears)

    Treating the service as a single process listening on one (or a few) ports has worked best for me, but if you want to start reading about networking options, here are some places to dig in:

    https://docs.docker.com/engine/userguide/networking/
    Docker’s official page on networking – a very high level introduction, with most of the detail on the default bridge behavior.

    http://www.linuxjournal.com/content/concerning-containers-connections-docker-networking
    More information on network layout within a docker host

    http://www.dasblinkenlichten.com/docker-networking-101-host-mode/
    Host mode is kind of mysterious, and I’m curious if it works similarly on windows.

    Allow access to internal docker networks from dev machine:

    route /P add 172.0.0.0 MASK 255.0.0.0 10.0.75.2
    

    Then use this https://github.com/aacebedo/dnsdock to enable DNS discovery.
    Tips:

    > docker run -d -v /var/run/docker.sock:/var/run/docker.sock --name dnsdock --net bridge -p 53:53/udp aacebedo/dnsdock:latest-amd64
    
    > add 127.0.0.1 as DNS server on dev machine
    
    > Use labels described in docs to have pretty dns names for containers
    

    So the answer on the original question:
    YES WE CAN!
    Oh, this not actual.

    MAKE DOCKER GREAT AGAIN!

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.