Boot2Docker: can't get ports forwarding to work

纵然是瞬间 提交于 2019-11-27 15:50:43

See Boot2docker workarounds:

You can use VBoxManage.exe commands to open those ports on the boot2docker VM level, in order for your actual VM host to access them.
By default, only the port 2222 is open, for boot2docker ssh to work and open an interactive ssh boot2docker session.
Just make sure VirtualBox is in your PATH.

  • VBoxManage modifyvm: works when the boot2docker VM isn't started yet, or after a boot2docker stop,
  • VBoxManage controlvm: works when the boot2docker VM is running, after a boot2docker start.

Let's say your Docker container exposes the port 8000 and you want access it from your other computers on your LAN. You can do it temporarily, using ssh:

Run following command (and keep it open):

$ boot2docker ssh -vnNTL 8000:localhost:8000

or you can set up a permanent VirtualBox NAT Port forwarding:

$ VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port8000,tcp,,8000,,8000";

If the vm is already running, you should run this other command:

$ VBoxManage controlvm "boot2docker-vm" natpf1 "tcp-port8000,tcp,,8000,,8000";

Now you can access your container from your host machine under

localhost:8000

That way, you don't have to mess around with the VirtualBox GUI, selecting the computer called boot2docker-vm from the list on the left, choosing Settings from the Machine menu (or press Command-S on a Mac), selecting the Network icon at the top, and finally clicking the Port Forwarding button.

boot2docker on Windows (and OSX) is running a VirtualBox VM with Linux in it. By default it exposes only the ports necessary to ssh into the VM. You'll need to modify the VM to get it to expose more ports.

Adding ports to the VM is more about configuring VirtualBox and less about boot2docker (it is a property of the VM, not the software running inside it). Please see the VirtualBox documentation for "port forwarding" and other network configuration. https://www.virtualbox.org/manual/ch06.html

Yes you need to open the ports in the Virtualbox machines:

enter image description here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!