Docker: Connectivity between Physical Machine – VM -Docker container

I have just started to have some experimentation with docker.
On my Windows host I have a virtual machine which holds a docker container. I want to have a communication between host and container or may be other VMs and this container.

  • Host ip is 192.168.2.10 with subnet mask 255.255.255.0
  • VM ip is 192.168.254.130 with subnet mask 255.255.255.0
  • Container gets an ip 172.17.0.13

I have seen few blogs talking about bridging but I am still not sure about it and how to do that. I am not very much into networking stuff.

  • docker push to dockerhub private repo sometimes pushes existing layer again (ubuntu base layer)
  • Running Tomcat with PostgreSql using Dockerfile
  • How to connect to client after installing db2 in docker?
  • Docker not starting “ could not delete the default bridge network: network bridge has active endpoints”"
  • docker, MYSQL_ROOT_PASSWORD do not work
  • Unable to migrate Django db when using docker container
  • A little guidance will help.

    Thanks

    EDIT:
    I followed this bridge-building but could not understand what ip range to give to bridge, so, I gave 192.168.254.1/24. The command ip addr show bridge0 shows state UNKNOWN.

  • What's the best way to compose multiple Docker images with different bases
  • Can not pull docker image from private repo when using Minikube
  • Cannot login to docker container registry which is inside docker container
  • curl Flask web service inside Docker container
  • Docker for Mac Beta: Unable to link containers properly
  • Dockerfile vs. docker-compose VOLUME
  • 2 Solutions collect form web for “Docker: Connectivity between Physical Machine – VM -Docker container”

    I’ll assume you are using Docker on Windows with Linux host running on Virtualbox. Note that by default docker-machine creates a NAT adapter (with a port forward) and a host-only adapter, sometimes it is tricky to get different machines to talk to the correct ip.

    As answered by Adrian you typically “publish” ports by port forwarding, but if your container has to communicate via many ports and you are only running one such container / host it could be easier to start the container via docker run --net host ..., this way host’s ethernet adapters are directly visible within the container (as I discovered here).

    The normal way to do this is just to publish a port on the container and use the IP of the VM e.g:

    docker run -d -p 80:80 nginx
    

    Then visit the IP of the VM in a browser running on your host and you should get the webpage.

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