Mark Thomas Miller's logo

Fixing address already in use

July 12, 2020

I was recently trying to run a Docker environment on a new Macbook Pro. However, I kept getting the error, Ports are not available: listen tcp bind: address already in use. If you're seeing this, try running curl localhost:80 and see if it logs:

<html><body><h1>It works!</h1></body></html>

If so, it's actually the result of web sharing being turned on, which runs an Apache server on this port. For some reason, this is enabled by default on Macs, and there's no option in the settings to turn it off. Just run this command in your terminal to stop it:

sudo apachectl stop

After I've run this, it hasn't started up again — even after I restart my system. And if you ever want to turn it back on, you can just run sudo apachectl start. The more you know!