Fixing address already in use

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.

About the author

I'm Mark Thomas Miller, a full stack engineer and designer currently working at ConvertKit. (We're hiring!) People like Arnold Schwarzenegger, Lindsey Stirling, and Tim Ferriss use features I've built to connect with their fans. I'm currently geeking out about Svelte, mechanical keyboards, and minimalist UI design, and replaying Ocarina of Time.