Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open port 7946 and 4789 in a VM which is created by docker machine

Tags:

docker

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
like image 371
dzhou Avatar asked Dec 27 '17 09:12

dzhou


1 Answers

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.

like image 103
Julien Avatar answered Sep 29 '22 02:09

Julien