The error message

Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use

That was the nice surprise I got when I switched back to a project and wanted to start some docker containers using "docker-compose up -d"

The context:

  • Mac os
  • Laravel app built with Laradock including a Nginx docker image

How to fix

First check what is using the port 80 by running

sudo lsof -i:80

In my case I got:

COMMAND   PID          USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
nginx   25348 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)
nginx   25349 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)
nginx   25350 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)
nginx   25352 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)
nginx   25353 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)
nginx   25354 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)
nginx   25355 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)
nginx   25356 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)
nginx   25357 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)
nginx   25358 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)
nginx   25359 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)
nginx   25360 gilbert_tchoi    6u  IPv4 0xXXXXXXXXXXXXXXXX      0t0  TCP localhost:http (LISTEN)

If you don't care, the brutal approach is taking all your PID and running them through

kill -9 myPID

Unfortunately, the list of Nginx came back in my case with other PID.

Random idea, let's check brew service by running brew services list

nginx          started root          /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

Culprit found for the unkillable Nginx. To clean up this nginx service that was probably a leftover from another project, just run

brew services stop nginx

Now I can start my docker containers and get back to my work.