Docker port 80 address already in use on macos, It works !

X anonymous
2 min readNov 22, 2023

--

What Happened ?

You are using your mac, and trying to start a docker container which binds the 80 port of your mac. However, you found it said 80 port already in use like this:

Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:80 -> 0.0.0.0:0: listen tcp 0.0.0.0:80: bind: address already in use

And your docker compose file may looks like this:

version: "3"

services:
elgg:
build: ./image_www
image: i-am-atomic
container_name: elgg-10.9.0.5
ports:
- 80:80
tty: true
depends_on:
- mysql
networks:
net-10.9.0.0:
ipv4_address: 10.9.0.5

Okay, I don’t care whether you use docker compose or not, this is just an example.

How to solve

Now please open your browser, go to localhost (Yes, no port is specified here, let it use default 80 port !)

Then you may see this:

Okay, that shows we encountered the same problem ! What’s the problem ?

There’s an apache server running on your mac !

To solve this problem, just do this:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null

Done.

Alternatively, you may also try this command:

sudo apachectl stop

This may help, but sometimes it can’t work by arguing this:

Could not reliably determine the server's fully qualified domain name...

So I would suggest you use the first command launchctl I provided above.

Now let’s check if there’s anything occupying 80 port:

sudo lsof -i :80

You should see nothing listed here now. If so, that means the problem have been addressed. You can now start your docker container on 80 port, or, maybe not just docker… anything you want to do with 80 port…

Stackoverflow

--

--