Docker Error in CLI: `Bind for 0.0.0.0:5432 failed: port is already allocated`

I’m seeing the following when running astro airflow start:

Error response from daemon: driver failed programming external connectivity on endpoint envoyastroairflow67f66e_postgres_1 (187ad99d5d17cb628336a598cec7bf7e7f593be89f5c995dcf60a21e0045b301): Bind for 0.0.0.0:5432 failed: port is already allocated

I ran astro airflow stop hoping that might fix but no luck

Running astro airflow start by default will start your project with the Airflow Webserver exposed at port 8080 and postgres exposed at port 5432.

If you’re getting this error, that means that you already have Postgres running locally on port 5432, assumedly for something else.

If you can and want to stop that Postgres from running, you can do the following:

  1. List running containers by running docker ps from your terminal
  2. Take the id and do docker stop {container_id} from there
    OR
    run docker stop $(docker ps -q) to stop all containers.

If you for some reason you can’t stop that Postgres from running, there is a way to change the port via a change to your config.yaml file. For that workaround, check out this forum post.