Npx directus-template-cli@latest init failed due to confliction of postgres port

2 Answers

2

Hey there! :waving_hand:

Welcome to the Directus community!

Looks like you’re running into a port conflict with PostgreSQL. This usually happens when you already have another Directus project (or any other service) running on the same port.

Quick fixes

Option 1: Stop your existing project

  • If you have another Directus project running, just Ctrl+C to stop it

  • Or check what’s running on port 5432:


# Check what’s using the PostgreSQL port

lsof -i :5432

Option 2: Change the port mapping

  • Open your docker-compose.yml file

  • Find the PostgreSQL service section

  • Change the port mapping from 5432:5432 to something like 5433:5432

  • This maps your local port 5433 to the container’s port 5432

Example:

services:
  database:
    ports:
    - "5433:5432"  # Changed from 5432:5432

Then just start it up with the new port mapping and you should be good to go!

You can also use the npx directus-template-cli@latest apply command to apply the backend template to an existing Directus instance - instead of rerunning init.

Hi Bryan,

Thank you for the detailed and very useful reply, the issue was solved now.

But here is a another question, why there is no more recommendation about initializing a new project with “npm init directus-project my-project“ in the document?

Because Directus relies on a couple of native dependencies that may or may not exist across environments. By using Docker as our primary distribution method we can avoid odd and hard to debug problems caused by subtle differences in hosting environment :)

What he said :rofl:. For what its worth - when I joined Directus years ago my experience with Docker was mostly "okay how do I avoid this thing" and now I truly can't work without it. Definitely a bit of effort to learn and understand, but so so worth it because of the headaches and stress it saves you from.

Thank you all for the reply :-)