How to open port 7946 and 4789 in a VM which is cr

2019-06-22 05:18发布

问题:

I’m working through “Get Started with Docker”, Part 4. My OS is Win10 64x. My app cannot be accessed through a web browser. I found a possible reason from the document.

Having connectivity trouble?

Keep in mind that in order to use the ingress network in the swarm, you need to have the following ports open between the swarm nodes before you enable swarm mode:

Port 7946 TCP/UDP for container network discovery.

Port 4789 UDP for the container ingress network.

I have tried to open thes ports in a VM which is created by docker machine. The driver is VirtualBox

$ docker-machine ssh default
                                        ##         .
                                  ## ## ##        ==
                               ## ## ## ## ##    ===
                           /"""""""""""""""""\___/ ===
                      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
                           \______ o           __/
                             \    \         __/
                              \____\_______/
                 _                 _   ____     _            _
                | |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
                | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
                | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
                |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 17.09.1-ce, build HEAD : e7de9ae - Fri Dec  8 19:41:36 UTC 2017
Docker version 17.09.1-ce, build 19e2cf6    
docker@default:~$ sudo -i
Boot2Docker version 17.09.1-ce, build HEAD : e7de9ae - Fri Dec  8 19:41:36 UTC 2017
Docker version 17.09.1-ce, build 19e2cf6
root@default:~# firewall-cmd --z one=public --add-port=7946/tcp --permanent
-sh: firewall-cmd: not found
root@default:~#  vi /etc/sysconfig/iptables
root@default:~# service iptables restart
-sh: service: not found
root@default:~# source /etc/sysconfig/iptables
-sh: /etc/sysconfig/iptables: line 1: -A: not found
-sh: /etc/sysconfig/iptables: line 2: -A: not found
root@default:~#  vi /etc/sysconfig/iptables
root@default:~# service iptables status
-sh: service: not found
root@default:~# yum install firewalld firewalld-config
-sh: yum: not found
root@default:~# apt get firewalld firewalld-config
-sh: apt: not found

However these ports cannot be open. The following code are written in the /etc/sysconfig/iptables

-A INPUT -p tcp -m state --state NEW -m tcp --dport 7946 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 4789 -j ACCEPT

回答1:

I've encountered the same issue here. I was actually not hitting the right port. In the first part of the tutorial, the webapp is on the port 4000. Try this, or update the docker-compose file to redirect the port 80 to 80.



回答2:

Check also if you need some port-forwarding between your VirtualBox VM and your localhost.
See "Boot2Docker: can't get ports forwarding to work" as an example:

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

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

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

If your app is not accessible through a web browser, forwarding the port 80 (or 8000 or 8080 depending on your container) is more likely to resolve the issue than the swarm ports.



标签: docker