28

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
  • 4,228
  • 2
  • 24
  • 30
user3365017
  • 371
  • 1
  • 3
  • 7

6 Answers6

27

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,025
  • 3
  • 39
  • 60
19

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,540
  • 19
  • 35
8

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
  • 181
  • 3
  • 6
4

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
  • 41
  • 1
1

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!!!

0

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
  • 553
  • 8
  • 17