Docker Mac Beta and container connecting to host ports? - python

I currently use PyCharm (Actually IntelliJ) and have been using Kitematic with VirtualBox support.
I have a container connecting to the host (which is a virtual machine) to do remote debugging.
The issue is when I try to use Docker Mac Beta, the container doesn't seem to be able to access any specific ports on the host but it can ping the host. Which doesn't make any sense...
Anyone have any ideas?
Is there some magic sauce I need to make the python debugger listen on all IPs/Ports maybe?
Edits:
To clarify, when running a python script in this environment, the script has to initiate an outbound connect to a specified ip/port.
Here's some console output to help understand:
This is inside the container itself. I have the debugger running on port 15001 on my Mac.
# /sbin/ip route|awk '/default/ { print $3 }'
172.17.0.1
# ping 172.17.0.1
PING 172.17.0.1 (172.17.0.1): 56 data bytes
64 bytes from 172.17.0.1: icmp_seq=0 ttl=64 time=0.078 ms
64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.066 ms
^C--- 172.17.0.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.066/0.072/0.078/0.000 ms
# telnet 172.17.0.1 15001
Trying 172.17.0.1...
telnet: Unable to connect to remote host: Connection refused
#
And then on the host (my mac):
➜ telnet localhost 15001
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
501 1 0.1 UNIX
This all works fine with the old virtualbox based Docker setup, which makes sense since its using full fledge virtual machines. But not sure how the new Docker Beta works, especially when it comes to networking.
I am using Docker-Compose for this, so I can set up the networking through the network configuration options but so far, I haven't gotten any random attempts to work.
Also, the container is able to access anything else (google.com or whatever), just not a specific port on the host machine.

I think the problem is that you need to expose port 15001.
Try adding to Dockerfile
EXPOSE 15001

Create a host-based loopback device and then use a remote_host alternative (like in xdebug) to configure your container to connect back to that host ( on the port ), this will solve your issue as it does for PHP ( same issue ). We had the same case when switching from dockertoolbox to docker for mac. See a configuration example including the launchdaemon to create the host loopback interface here: https://gist.github.com/EugenMayer/3019516e5a3b3a01b6eac88190327e7c

Related

How to connect to a socket server on the host machine via the virtual machine?

I did the port forwarding: I put the server on the virutal machine, and connected the client from the host to the virtual machine. That worked well.
But now, when I tried to do this in the reverse direction, it did not.
First thing I did is a port forwarding with the following parameters:
host port: 35001
port to forward: 35001
virtual machine ip: 192.168.40.130
It was done succesfully.
After that, when I did this (server script but on cmd (shell) on host):
s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
s.bind(("0.0.0.0",35001))
I get this error:
Only one usage of each socket address (protocol/network address/port) is normally permitted
I believe that is because there is a process listening on the port 35001.
It is VMware(NAT) listening on 35001, after I forwarded the port (I find that out using netstat).
So how to make a server on the host, make it listening to port 35001, and be able to connect to it from a virtual machine?
It is windows 10 pro, python3, a windows 7 VM. Firewalls are disabled. I don't want to use a bridged connection.
The Vmware portforwarding is just a process, created by the vmware service, with the following parameters:
it runs on your host machine
allocates the TCP port 35001
listens to incoming TCP connections
forwards them to the TCP 35001 of your guest machine IP
This is what is does, and no more.
As your started the port forwarding, this process was started and allocated the 35001 TCP port on your host.
This is why your python script, on the host, did not work. It could not allocate the 35001 TCP port of your host again.
VMware creates a virtual network. Your virtual machines see this virtual network. No ethernet card belongs to it, but it looks as if it would. It has the 192.168.40.0-192.168.40.255 IP address range. Also your host machine is on this virtual network, probably with the IP 192.168.40.1. Your guest machine sees it as a router.
This is so for the host-only, bridged or NATted virtual network types. The virtual network types only affect, what your host machine does with the packets to forward them between the virtual and your physical network.
To run a server on your host, what you can connect from your guest, you do not need any port forwarding. Simply stop it, so your python script will run. Then, connect 192.168.40.1:35001 from your guest.

Openshift bind TCP port

I'm trying to deploy a python TCP listener on Openshift but I'm failing to understand how to manage external ports.
Googling and searching on Openshift's own KB, this article is mentioned lots of times but is no longer available. My TCP server app listens on port 8080 (as per $OPENSHIFT_PYTHON_PORT) and I'm trying to connect to it from the Internet on port 8000. Nevertheless, doing this means that a client app can establish a connection even if the server app is not started.
Does anyone have specific information on how to do this?
You can not make raw tcp connections to your OpenShift gears, you can only make http (80/443) and ws (8000/8443) connections. Both types of connections go through a proxy on the node, http goes through an apache proxy, and ws goes through a node proxy. If you want to make raw tcp connections you would have to use port forwarding from your location machine, and make sure that you are publishing the port information through a custom cartridge.
An Internet Archive grab of the removed KB article you mentioned says you could bind to internal ports 15000 to 35530. But this has now changed: my test OpenShift box didn't let me bind to any localhost port. Its $OPENSHIFT_PYTHON_PORT is accessible from the outside via normal Web ports (80 and 443; SSL decryption is done for you on 443). If you need other ports you probably need something other than Openshift.

Cannot connect to python -m SimpleHTTPServer server

this this probably a very simple question, but I haven't been able to find an answer anywhere. On the online articles about it, they didn't show the exact process to share a directory using SimpleHTTPServer. I've run the command successfully and have the server running, but I can only access it on the machine that started it.
192.168.1.2:8000
I've tried it on a Windows machine and iPad (although that doesn't really make a difference) on the local network. To access it, I've been using my local IP address, which I found by running ifconfig | grep inet, which returns (among other matches):
inet 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255
And after searching a bit online, I found: https://github.com/shbhrsaha/instant-sharing/blob/master/share.py.
There's function which supposedly gives you a handy url to share with your friends, but I tried running locally, and all I got was "localhost.localdomain", which obviously returns 127.0.0.1
How can I make this work?
When you start SimpleHTTPServer it tells which IP addresses it is listening to:
python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
Address 0.0.0.0 means it listening to all available IP addresses. Thus in this case you should simply reach the server by going http://192.168.1.two:8000
If it doesn't work then it is most likely a network issue. You can test this out with telnet command (both Windows and UNIX available): telnet will open a TCP/IP connection on a certain IP and certain port.
E.g. on UNIX you can do:
telnet 192.168.1.2 8000
If you get:
telnet 192.162.1.2 8000
Trying 192.162.1.2...
telnet: connect to address 192.162.1.2: Connection refused
telnet: Unable to connect to remote host
... it means SimpleHTTPServer is running.
If it waits for very long time it means your router/firewall is blocking the connection.
If you get a reply:
telnet localhost 8000
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
... browser should work as well. You can quit telnet by just keep hitting the enter (the SimpleHTTPServer will close the connection).
In Ubuntu
I had the same problem, then I narrowed it down to be a firewall problem.
First, check if your firewall is active.
sudo ufw status
If it is active by default it blocks all incoming connections from anywhere.
You can check whether you have granted access to your running port. The following command will list down all the available rules. if your port is not there with access given to other ports then you need to grant access.
sudo ufw status numbered
[This is what the issue] Now grant access on the port for desired ip addresses/ all. I allowed all incoming connections to the port 8000 on all ip adress by following command.
sudo ufw allow from any to any port 8000 proto udp
Initially, I thought this should be tcp instead of udp but worked with udp only. Something to dig up later.
The server was running, and we could access it, but only on the server's machine.
There was something blocking the connection, and that was The Firewall.
We configured The Firewall and it worked fine, my other device could get access.

Send a string from windows to vmware-ubuntu over socket using python

I am trying to send a string from the windows to the linux vmware on the same machine.
I did the following:
- opened a socket on 127.0.0.1 port 50000 on the linux machine and reading the socket in a while loop. My programming language is python 2.7
- send a command using nc ( netcat ) on 127.0.0.1 port 50000 from the windows machine ( using cygwin ).
However, I dont receive any command on the linux machine although the command sent through windows /cygwin is successful.
I am using NAT ( sharing the hosts IP address ) on the VMWARE Machine.
Where could be the problem?
When you use NAT, the host machine has no way to directly contact the client machine. All you can do is usign port forwarding to tell vmware that all traffic directed to the designated ports on the host is to be delivered to the client. It is intended to install a server on the client machine that can be accessed from outside the host machine.
If you want to test network operation between the host and the client, you should configure a host-only adapter on the client machine. It is a virtual network between the host and the client(s) machine(s) (more than one client can share same host-only network, of course with different addresses)
I generally configure 2 network adapters on my client machines :
one NAT to give the client machine an access to the open world
on host-only to have a private network between host and clients and allow them to communicate with any protocol on any port
You can also use a bridged interface on the client. In this mode, the client machine has an address on same network than the external network of the host : it combines both previous modes
Your problem is multi-fold
1st
setup Ubuntu-VM's IP-network & a static IP-address of this guest O/S.
VALIDATE:
$> ifconfig // list all setup Ubuntu interfaces/addresses
2nd
if your VM guest is hosted as being connected to a different IP-network, than your Windows system, make sure there is a connectivity and route between these two hosts ( VMnet configurator in VmWare will help a lot to solve this ).
VALIDATE:
C:\ ping <aUbuntuVmIpADDRESS> // prove an online visibility Win->UbuntuVM
3rd
make sure your Windows O/S permits the use your selected TCP-port#
VALIDATE:
list all allowed / add if-needed TCP-port# in Windows Firewall setup
4th
make sure your python sends all socket-traffic not to a Windows local loopback interface <127.0.0.1>, but towards the visible IP-address of the Ubuntu-VM guest O/S, ( setup as per step-1, verified as per step-2 ) using an unused, permitted TCP-port# ( verified/setup as per step-3 )

Problems connecting to a server running on a (sometimes virtualized) Windows machine

***Sorry for using the Term Host & Guest I see that has confused things slightly. By Host I mean Client which listens on your desired port for incoming connections and by Guest I mean Server which attempts to retrieve the IP of your pre-defined Dyndns.org address. Then tries a connection. You may say that's 'backwards' but for my applications scenario that's the fitting method. Since I'm in the United Kingdom my public IP I mentioned starts with 91.
Here's two diagrams to explain if the Server connections to the Client running on the same OS.
Ubuntu - Linux
Connection over 127.0.0.1 = SUCCESS!
Connection over public IP = SUCCESS!
Windows - Laptop TinyXP - Laptop Vista - VM TInyXP
Connection over 127.0.0.1 = SUCCESS!
Connection over public IP = FAILED!
So the problem is Windows. I've tried the Twisted examples and again they work over local host but not via public IP on Windows so it can't be my script. It can't be the firewall as the two TinyXP installations don't have the default firewall, whilst the Vista laptop did have the default shipped one however I unblocked the process after it popped up prompting me. and thus did not yield any better results.
To forward the port I went to my Orange Livebox's configuration page (192.168.1.1) and forwarded the TCP port 4005. Just as I did for when I tested it on Ubuntu (Instead using the 4004 port) so it can't be that either. I attempted to use wireshark (Found it hard to understand). I started capturing packets on all ports, then fired up the Client followed by the Server. Resulting entries are here http://pastebin.com/ddytpydz
Alas I have no more ideas on what I can do. The twisted version I'm using is one of the latest whilst the Python version is 2.6 Any one have some ideas?
So maybe there is some windows limitations for listenings pors. As far as I remeber some Windows can have max 5 ports open for listening. But I don't remeber exacly.
Sounds like a firewall problem. I would add either the port or python.exe to the approved list.
Are any of the Windows machines joined to a domain?

Categories