0

1) Have tcp-server console application in host system Windows Server 2016

2) Have tcp-client console application in docker container based on windowsservercore

I can't connect from tcp-client to tcp-server.

Dockerfile:

FROM microsoft/windowsservercore 
ADD . /
EXPOSE 9595
ENTRYPOINT ExampleTcpClient.exe

Docker run command:

docker run -p 9595:9595 --rm mycontainer

How to connect to docker host from container on Windows 10 (Docker for Windows) I get Ip 172.18.112.1 by command ipconfig, but have error in tcp-client:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 172.18.112.1:9595

I tried several combinations:

tcp_server - 127.0.0.1:9595, tcp_client- 127.0.0.1:9595

tcp_server - 127.0.0.1:9595, tcp_client- 172.18.112.1:9595

tcp_server - 172.18.112.1:9595, tcp_client- 172.18.112.1:9595

tcp_server - 127.0.0.1:9595, tcp_client- 172.17.0.1:9595

tcp_server - host_static_ip:9595, tcp_client- 172.17.0.1:9595

tcp_server - host_static_ip:9595, tcp_client- 172.18.112.1:9595

tcp_server - host_static_ip:9595, tcp_client - host_static_ip:9595

If i start tcp_server in host system and start tcp_client in another machine with config: tcp_server - host_static_ip:9595, tcp_client - host_static_ip:9595, then it's work (without docker).

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
kepo4ka
  • 1
  • 1
  • For the container to connect out to the host you need something like `--network=host`. Using `-p` only sets up port forwarding into the container network which is otherwise fully isolated from the host. – TypeIA Mar 19 '18 at 18:43
  • Please check if your docker container is still running with `docker ps`. Normally a docker container does exit as soon as no process is running anymore. – dsdel Mar 19 '18 at 20:18
  • Docker is running because tcp client same time try to connect, and I set thread.sleep() – kepo4ka Mar 20 '18 at 04:29
  • TypeIA, https://stackoverflow.com/questions/40746453/how-to-connect-to-docker-host-from-container-on-windows-10-docker-for-windows#comment79498987_40789612 "Your answer does not work for Windows and Mac atm. --net="host" only works for Linux. On Mac you can access host Machine by name docker.for.mac.localhost, on Windows there is no such name and you can get bridge IP address with ipconfig" – kepo4ka Mar 20 '18 at 04:31
  • @TypeIA, I try start command in docker container: `ping 172.18.112.1` - it work; `ping static_ip` - it don't work; – kepo4ka Mar 20 '18 at 09:05
  • @TypeIA, I intall IIS server and in application i triyed using `WebClient wc= new WebClient(); wc.DonwloadString("http://172.18.112.1/"); wc.DonwloadString("http://static_ip/");` It don't work (error: Unable to connect to the remote server); – kepo4ka Mar 20 '18 at 09:10
  • if tcp_client app in docker container and tcp_server app on another vps machine, then they can connect. I haven't idea how do it on one machine, because applications in docker container can't connect to application on host system... – kepo4ka Mar 20 '18 at 10:02
  • @kepo4ka OK, I don't have any experience with Docker for Windows or with Windows containers. Sounds like the networking is a bit different. My apologies – TypeIA Mar 20 '18 at 14:10

0 Answers0