简体   繁体   中英

System.Net.Sockets.SocketException: 'An attempt was made to access a socket in a way forbidden by its access permissions.'

I have a tcp listener in a local app and a docker container with another app inside. In the docker container I expose the port 5555:5555 for establish a socket between the app inse docker to the tcp listner who is listening in 127.0.0.1:5555.

The problem is that when I expose the port in the docker container (-p 5555:5555) windows exclude this port.

enter image description here

that's why I can't run my tcp listener, reason why I get the System.Net.Sockets.SocketException: 'An attempt was made to access a socket in a way forbidden by its access permissions.'

I didn't find a solution for this, so at the end I created a new container for my tcp server, and I established a network between containers.

docker network create --driver bridge nat

Defining the networks in the docker-composes and giving to my tcpServer a static ip

services:
  tcpServer:
    networks:
      test:
        ipv4_address: 172.18.192.157
    ....

networks:
  test:
    external:
      name: nat

I tried first to set up the host network, but I realized that this funcionality is not available in windows.

  • The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server

Docker network documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM