关于vagrant端口映射的问题

来源:4-4 Docker bridge0详解

sliverg

2019-01-14

老师你好:
我在vagrantfile中添加了

config.vm.network "forwarded_port", guest: 5000, host: 5000

然后使用vagrant reload命令重启,输出

➜ vagrant reload
==> web: Attempting graceful shutdown of VM...
==> web: Checking if box 'centos/7' version '1811.02' is up to date...
==> web: Clearing any previously set forwarded ports...
==> web: Fixed port collision for 22 => 2222. Now on port 2201.
==> web: Clearing any previously set network interfaces...
==> web: Preparing network interfaces based on configuration...
    web: Adapter 1: nat
    web: Adapter 2: hostonly
==> web: Forwarding ports...
    web: 5000 (guest) => 5000 (host) (adapter 1)
    web: 22 (guest) => 2201 (host) (adapter 1)
==> web: Running 'pre-boot' VM customizations...
==> web: Booting VM...
==> web: Waiting for machine to boot. This may take a few minutes...
    web: SSH address: 127.0.0.1:2201
    web: SSH username: vagrant
    web: SSH auth method: private key
==> web: Machine booted and ready!
[web] GuestAdditions seems to be installed (6.0.0) correctly, but not running.
Redirecting to /bin/systemctl start vboxadd.service
Redirecting to /bin/systemctl start vboxadd-service.service
==> web: Checking for guest additions in VM...
==> web: Setting hostname...
==> web: Configuring and enabling network interfaces...
==> web: Rsyncing folder: /Users/s/Vagrant/centos7/ => /vagrant
==> web: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> web: flag to force provisioning. Provisioners marked to run always will still run.

~/Vagrant/centos7 took 39s 

看输出日志没有任何的错误,但是我在宿主机上使用telnet去访问5000端口一直失败。

~/Vagrant/centos7 took 18s 
➜ telnet 192.168.100.100 5000
Trying 192.168.100.100...
telnet: connect to address 192.168.100.100: Connection refused
telnet: Unable to connect to remote host

~/Vagrant/centos7 took 31s 

请问这个问题怎么解决啊??????

写回答

1回答

麦兜搞IT

2019-01-15

您好。

第一,确保主机上能ping通192.168.100.100

第二,您的vagrant上有什么服务开启了5000端口么,首先要确保你在vagrant主机内部能通过telnet 127.0.0.1 5000 连接上。

0
2
麦兜搞IT
回复
sliverg
嗯,那您的vagrant主机上开通了什么服务监听5000端口么,确保服务是运行的,否则5000端口打开了,没有服务监听也是不行的。 比如您如果想telnet 127.0.0.1 80, 那80端口必须是开的,比如nginx,apache都可以。
2019-01-16
共2条回复

系统学习Docker 践行DevOps理念

无论你是开发、测试还是运维,Docker都是你的必备技能。

3297 学习 · 1895 问题

查看课程