Search code examples
dockerboot2docker

Docker access port running on host


I'm using boot2docker and am running a docker container. I'd like for that docker container to be able to talk to my host who has an open port. I've tried hitting the host box, but its going through virtualbox so it seems there needs to be two levels of bridging here to get the ports to talk. Not sure how to do that, or even if its possible.


Solution

  • Actually you are right, there are 2 levels:

    Host <-> boot2docker VM <-> docker container

    so if you open a port while you run your container, the port can be accessed from boot2docker VM but not the host, unless you make a port forwarding.

    and here are two solutions:

    • access using boot2docker VM's ip but not localhost
      run boot2docker ip and you will see an ip address such as 192.168.59.103, then you can access your service through 192.168.59.103:port

    • make a port forwarding open your VirtualBox application, select virtual machine namely boot2docker-vm, goto Settings->Network->Advanced->Port Forwarding. Then you can add your own port to forward, for example, i'd like to access my ssh port through localhost:10022, just simply add a new column with host port 10022 and guest port 22. you can check this doc for more infos.

    if you want access host port from container, here is a simple way, just expose your host ip to docker container's host, like docker run --add-host vmhost:192.168.59.3 <docker_image> <command>, note that 192.168.59.3 is the default virtualbox host only adapter IP. Then you can access vmhost as you want.

    Also, you can manage your own network bridge to do this, and pipework may help you.