41

I'm trying to run the following docker command (latest Win10 Fall 2018 update, latest docker version 2.0):

docker run -d -p 1433:1433 -e sa_password=Test_123 -e ACCEPT_EULA=Y microsoft/mssql-server-windows-developer

But it fails wit the following error:

Error response from daemon: failed to create endpoint unruffled_wozniak on network nat: hnsCall failed in Win32: The process cannot access the file because it is being used by another process. (0x20).

I've tried the following:

  • restart daemon
  • docker system prune -a
  • restart machine
  • restart HNS service
  • reinstall docker
  • disable from Windows features the container and Hyper-V

Nothing worked. Any suggestions?

juanlumn
  • 6,155
  • 2
  • 30
  • 39
user3365017
  • 501
  • 1
  • 4
  • 7

9 Answers9

50

Not sure how wise this is, but I checked the port wasn't in use with another app and still got the error.

This has fixed the issue a couple of times for me. In an Administrative PowerShell console, run the following:

Stop-Service docker
Stop-service hns
Start-service hns
Start-Service docker
docker network prune

Partially sourced from this post.

Andy Joiner
  • 5,932
  • 3
  • 45
  • 72
  • 1
    This applied to my situation where the port was definitely not in use. It was like Docker had got itself confused about which ports were in use and just wouldn't let me use one that was definitely available. This series of commands at an admin prompt did the trick. I noticed that it removed the network "WSL" when I did it, which didn't happen during `docker network prune` previously at non-admin powershell. Maybe the "WSL" network is the key? – theyetiman Jan 24 '22 at 12:32
  • Thanks, this worked for me also. Nothing was using the port. I'm wondering if just pruning the network may have been enough. – Paul George May 12 '22 at 11:32
  • The restarting of the services worked for me without the prune. Thanks – Duncan Howe Oct 12 '22 at 10:55
25

I had the same issue while trying to get PostgreSQL running with Docker. The problem was that the port was already tied up! This was because I had already had PostgreSQL running as a normal database in my OS.

My fix was finding the postgresql-x64-10 service in the Task Manager (under Services) and stopping the service.

the solution probably sounds obvious but I thought I'd mention it anyway

harvzor
  • 2,832
  • 1
  • 22
  • 40
10

I was running into the same error, but stopping the SQL Server service running on my local machine on port 1433 wasn't an option, so I simply mapped a different port to the container. I replaced the port mapping parameters with the following:

-p 1434:1433

This will map your local machine's port 1434 to the container's port 1433. If your local machine's port 1434 is also in use, you'll have to find a port that is available for you.

Once you have that in place, if you want to get in with SSMS, you'll just need to tell it to connect over port 1434 by using a comma:localhost,1434

SQL Server Connection Dialog

Nick Ligerakis
  • 301
  • 4
  • 7
5

This occurs in windows if you are in docker with linux containers and there is a pending container which uses the port in windows containers. Try switching the containers to different os and stopping the container process. This worked for me.

bhavya
  • 51
  • 1
  • 1
5

On windows check ports Listener: PS:> Get-NetTCPConnection | findstr 1433

in my case: enter image description here

find process with ID = 12240 and kill them (com.docker.backend)

after my new port redirect work well!!!

Taras Lisniak
  • 71
  • 1
  • 5
2

Seems like there's a difference between Linux's and Windows' error messages.

Command:

docker run -d -p 80:80 my_image

Linux's error message:

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

Windows' error message:

docker: Error response from daemon: failed to create endpoint admiring_matsumoto on network nat: failed during hnsCallRawResponse: hnsCall failed in Win32: The process cannot access the file because it is being used by another process. (0x20).

After changing the command to

docker run -d -p 81:80

Worked on both.

Then, I was able to see that, in my case there was a Windows Defender crashed service (that should be stopped) 'holding' port 80 and I could use port 80 again.

tgarcia
  • 675
  • 9
  • 21
2

Just switch to Linux container, this helped me

enter image description here

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
1

Setting the Windows system dynamic port range can be solved

netsh int ipv4 set dynamicport tcp start=35001 num=30535
0

In my case, the issue was that the port that I was trying to bind to (50055) was being reserved by the OS.

To view Windows' reserved port ranges:

netsh interface ipv4 show excludedportrange protocol=tcp

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
      5357        5357
     49677       49776
     49877       49976
     50000       50059     *
     50160       50259
     50360       50459
     50564       50663
     50664       50763

* - Administered port exclusions.

I removed the offending port range by running (as admin):

netsh int ipv4 delete excludedportrange protocol=tcp startport=50000 numberofports=60

Though this worked for me, removing these reservations isn't always this straight forward.

See this SO question for more details.

Also relevant: https://github.com/docker/for-win/issues/3171

Lawrence
  • 133
  • 2
  • 6