-1

I’m trying to run a PostgreSQL container in Docker on my MacBook Air, but I’m getting the following error:

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

Additional information: • OS: macOS (MacBook Air) • Docker: Latest version installed via Homebrew • PostgreSQL: Installed via Homebrew (brew install postgresql)

Any help is greatly appreciated! 🙏

1
  • Check if you have a stopped container using the port using docker ps -a. If you do, then remove the stopped container using docker rm <container name>. Commented Feb 20 at 13:30

1 Answer 1

0

✅ How to fix it

The issue happens because PostgreSQL is already running on your Mac and is using port 5432, which conflicts with your Docker container. Here’s how you can resolve it:

1️⃣ Stop PostgreSQL properly on macOS

Since you installed PostgreSQL via Homebrew, the correct way to stop it is:

brew services stop postgresql

Then, check if the port is still in use:

sudo lsof -i :5432

2️⃣ Kill the process manually (if needed)

If PostgreSQL is still running, force it to stop by killing the process:

sudo kill -9 521  # Replace 521 with the actual PID

Then, verify again:

sudo lsof -i :5432
Sign up to request clarification or add additional context in comments.

1 Comment

OP installed Docker using Homebrew. Not PostgreSQL.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.