这几天在玩docker,需要将虚拟机里的docker的端口映射到本机,这样本机才能访问。下面是我的方法。
macOS Sierra 10.12.1
VMware Fusion 专业版 8.5.2 (4635224)
我虚拟机是NAT方式,首先打开/Library/Preferences/VMware Fusion/vmnet8/nat.conf
cd /Library/Preferences/VMware\ Fusion/vmnet8
vim nat.conf
在这下面添加映射规则,比如注释条目里面的虚拟机80端口映射到本机的8080端口:
[incomingtcp]
# Use these with care - anyone can enter into your VM through these...
# The format and example are as follows:
#<external port number> = <VM's IP address>:<VM's port number>
#8080 = 172.16.3.128:80
这时候重启VMware服务或者重启一下,通过http://localhost:8080/就可以访问虚拟机的80端口了,此时只要虚拟机里的docker有用-p转发docker的端口的话就可以实现从本机访问docker的服务了。
等再玩一段时间就来写篇关于docker的文章。