Search code examples
dockerdocker-composetcptcp-port

Docker connect to TCP port 1433 Erratically throws error "1433 An attempt was made to access a socket in a way forbidden by its access permissions "


At work, we have a Docker Compose YAML file will allow the programmer to run an MS SQL Server-based docker image as a container.

Please keep in mind that there are configurations for 3 images ( 2 Database images & 1 Hasura GraphQL image ) in said Docker Compose YAML file:

a) Microsoft SQL Server Database which is used by the application in question that is being developed

b) PostgreSQL database and a database instance specifically for storing Hasura's Metadata info data

c) Hasura GraphQL instance

Here are the steps that I take to run said YAML file in docker.

  1. Start the docker desktop application.

  2. Retrieve said Docker Compose YAML file, and place it in a directory on your local computer.

  3. In this gitlab.com repo's Docker Compose YAML file, default HOST_PORT and CONTAINER_PORT numbers were entered, therefore, navigate to said directory within Microsoft Power Shell, and run the following command:

    docker-compose -f ms_sqlserverdocker-compose.yml up

Unfortunately, I sometime get the following error message Erratically when I run the Microsoft SQL Server Database container ( i.e. sql-server-db ) :

enter image description here

The error states the following: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:1433 -> 0.0.0.0:0: listen tcp 0.0.0.0:1433: bind: An attempt was made to access a socket in a way forbidden by its access permissions

( I usually resolve the aforementioned error by restarting my local computer which is really onerous because it’s sort a pain to restart the computer in order to to free up a port )

The aforementioned error comes up erratically in my local computer.

When I the following netstat command in my MS Dos commandline window, it returns nothing which is strange:

Microsoft Windows [Version 10.0.19045.2965] (c) Microsoft Corporation. All rights reserved.

C:\Windows\system32>netstat -ano | find "1433"

C:\Windows\system32>

If netstat searches for port 1433 , and return nothing then does it mean that port “1433” is available and open for use? If yes then why is docker complaining with the following message when I attempt to connect to port 1433 within my local computer?

An attempt was made to access a socket in a way forbidden by its access permissions

( I usually resolve the aforementioned error by restarting my local computer which is really onerous because it’s sort a pain to restart the computer in order to to free up a port )

Does anyone know why the 1433 port becomes erratically unavailable? Furthermore, is there a more elegant way of freeing up said port?


Solution

  • All credit to @eric-herlitz for his following webpage that contains the answer:

    (Reference Citation Listing: https://www.herlitz.io/2020/12/01/docker-error-ports-are-not-available-on-windows-10/ )

    "Windows 10 can sometimes hog ports and sockets preventing us from using them with services like docker. This renders error like this

    docker : Error response from daemon: Ports are not available: listen tcp 0.0.0.0:1433: bind: An attempt was made to access a socket in a way forbidden by its access permissions. At line:1 char:1 +docker start sqlexpress +~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Error response ...ss permissions.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError

    Error: failed to start containers: sqlexpress

    Stopping winnat

    To fix this you must temporarily disable the winnat service, this is simply done by running this command (must be run as administrator)

    net stop winnat

    Start your docker services and start winnat again

    net start winnat

    "

    (Reference Citation Listing: https://www.herlitz.io/2020/12/01/docker-error-ports-are-not-available-on-windows-10/ )