Cannot use internal ports that the host already uses

Hello, I have a problem that I cant resolve.

Internal container ports cannot be used if the same port is occupied by the host.
I’ve tried with two different images, nginx:latest and mysql:8.0 and both fails to bind to their default ports.

Im currently on docker version 4.18.0 (104112)
Windows 11 Pro 22H2 for x64-based Systems (KB5025239)

and this is the commands that I use:

nginx

docker run nginx

mysql

docker run -e MYSQL_ROOT_PASSWORD=*************** mysql:8.0

Both port 80 and 3306 are occupied by the host machine.
MySql container starts without problems when I stop the service that are using port 3306.

Things that I have tried:

  • system prune -all
  • reinstall docker desktop for windows. ← This worked a short period of time but now the problem is back
  • update to latest version v4.18.0 (104112)
  • turn off experimental features
  • create a new network and let containers use the created network instead of the default
  • ensure that Im using wsl2
  • restart computer

Any ideas?

I have the same issue. I had to reinstall docker and WSL last week, which helped but lasted for a few days, today the issue reappeared again.
Also found the same issue on Stack Overflow posted recently:
WSL2 docker .NET container Failed to bind to address http://[::]:80: address already in use - Stack Overflow

However, issue does not seem to be related to docker version. I have uninstalled Docker 4.18.0 and installed version 4.13.0. After several restarts the issue appeared again.

In my docker-compose file multiple services use default port 80, which they don’t expose to the host.

Docker versions tested 4.13.0, 4.18.0

Edition Windows 11 Enterprise
Version 22H2
Installed on ‎2022-‎10-‎25
OS build 22621.1555
Experience Windows Feature Experience Pack 1000.22640.1000.0

I had the same issue. All of my containers were working fine on Friday, but starting Saturday morning I couldn’t get any of them that were binding to port 80 internally to start without giving me similar exceptions. I was also getting the same errors when trying to run nginx.

Docker Desktop for Windows versions tested: 4.15.0, 4.16.3, 4.17.1, 4.18.0

Edition Windows 11 Pro
Version 22H2
Installed on ‎10/‎28/‎2022
OS build 22621.1555
Experience Windows Feature Experience Pack 1000.22640.1000.0
WSL Version: 1.2.0.0

What I had tried, none of which has allowed me to successfully start any containers that internally bind to port 80:

  • Clean/Purge data
  • Reset to factory defaults
  • Reinstalled docker desktop for Windows 4.18.0
  • Installed docker desktop back to 4.15.0
  • Restarted computer multiple times
  • Uninstalled Windows Update KB5025239 that had been applied late last week (took OS build back to 22621.1413 and experience pack to 1000.22639.1000.0)
  • wsl --update in Powershell, but result was The most recent version of Windows Subsystem for Linux is already installed.

I have another machine that is working fine. It’s currently running 4.18.0 and has the same WSL2 setup, the only difference is it’s running Windows Home.

Edition Windows 11 Home
Version 22H2
Installed on ‎11/‎1/‎2022
OS build 22621.1555
Experience Windows Feature Experience Pack 1000.22640.1000.0
WSL Version: 1.2.0.0

I ended up running:
wsl --update --pre-release
Which updated my WSL version to 1.2.3.0. After that, I was able to run docker run nginx:latest and it started without the previous errors. I’m also able to start my other containers like before.

Interestingly enough, though, my Windows Home machine is still working without applying this update.

I think the error might be related to the fix noted in Release 1.2.1

2 Likes

This fixed issue for me as well, I had version WSL version 1.2.0 installed, which is now marked as pre-release.
Apparently, I believe this WSL version was briefly released and then demoted to pre-release.

1 Like

Life saver, my coworker and I use Lando for PHP projects and we were having all kinds of issues. I ran the update to pre-release and no more issues.

wsl --update --pre-release

Thank you for the detailed reply!
Looks like wsl --update --pre-release worked :slight_smile: