Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

boot2docker - Port forwarding in docker-machine?

Since boot2docker is deprecated I've switched to docker-machine but I don't know how to open a port from docker-machine. In boot2docker I could do like this:

boot2docker ssh -L 27017:localhost:27017

This would forward port 27017 from VirtualBox to localhost 27017 as long as the SSH connection is open. Note that I'm not looking for a way to open the port permanently in VirtualBox. How can I achieve this with docker-machine?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can still access the VBoxmanage.exe command from the VirtualBox used by docker machine:

VBoxManage controlvm "boot2docker-vm" natpf1 "tcp-port27017,tcp,,27017,,27017";
  • Use docker-machine info to get the name of your vm.
  • use modifyvm if the vm isn't started yet.

See a practical example in this answer.


That is the current workaround, pending the possibility to pass argument to docker-machine ssh: see issue 691.

The other workaround is to not forward port, and use directly the IP of the VM:

 $(docker-machine ip default)

As commented by sdc:

You can confirm that port forwarding is set up correctly with

 VBoxManage showvminfo boot2docker-vm | grep "NIC.* Rule" 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...