Windows – “bind: An attempt was made to access a socket in a way forbidden by its access permissions”

dockernetworkingportrouteswindows

Say we have frontend and backend containers based on Docker Desktop (for Windows).

Backend container uses port 9001, and the frontend container listens to 9001.

The problem is that port 9001 is already in use by Windows 10 by the Intel driver, and it is impossible to run a container on this port:

Error response from daemon: Ports are not available: listen tcp 0.0.0.0:9001: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

Could you please advise what is the way to handle this port if there is no ability to change it directly from application code?

Best Answer

A couple of ways:

  • When either using a docker run command, specify the host port to use, and set it to something other than 9001. i.e. -p 9002:9001 or Docker Compose, i.e.
ports:
      - '9002:9001'

Then use port 9002 instead of 9001 when accessing the container from the host (Win 10).

  • Use Nginx and set up a reverse proxy, leave the host port empty when starting the container so no external post is opened on the host, and have the reverse proxy pass it over to the container's 9001 port.