Docker failed to start n8n and deploy postgresql?

Describe the issue/error/question

What is the error message (if any)?

Please share the workflow

(Select the nodes and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow respectively)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:0.205.0
  • **Database you’re using (default: SQLite):

    **
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]:

Hi @Tk8and15, this suggests your n8n docker container can’t talk to Postgres on port 5432. From looking at your screenshot it seems you are only launching n8n, so I am not sure whether you are running PostgreSQL also via docker or directly on your server.

The docker run command from your screenshot would use the default bridge networking mode unless I am missing something. This means that your containers are isolated from each other, but can talk to each other using the respective container name as the hostname. So if your Postgres container is called db, you’d need to use db as the hostname.

If Postgres runs on your host machine, you probably want to use a hostname of host.docker.internal to reach your host as described here in the Docker documentation.

I still don’t understand after reading it. Can you use the startup command to list? In this way, it will be more intuitive and understandable.

Hey @Tk8and15,

Postgres isn’t running on localhost in the n8n container.

Are you running Postgres in another container or is it on your host?

You might be able to use 172.17.0.1 as your Postgres host address but this all depends on your environment.

I actually run postgres on the host. How can I run postgres in an n8n container?

You would run it in its own container. But since Postgres is already running you shouldn’t need to. Simply use host.docker.internal to reach your host from inside your container.

The IP shared by @jon will also work in most cases, but Docker suggests you avoid using it (as it can change):

The host has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS name host.docker.internal which resolves to the internal IP address used by the host. This is for development purpose and does not work in a production environment outside of Docker Desktop.

If you want to run Postgres in a container instead you can check out the docker compose example from our repository: n8n/docker/compose/withPostgres at master · n8n-io/n8n (github.com)

If I use the Docker Run command to execute it, how can I change it? Do you have an example? Let me refer to it.

In your docker run command simply replace -e DB_POSTGRESDB_HOST=localhost with -e DB_POSTGRESDB_HOST=host.docker.internal.

Thank you very much for helping me solve the problem. I’ve tried. The n8n instance can be started, but Postgres is still not connected.

Hm, that seems odd. n8n being able to start would suggest it can talk to the database. Which database is your n8n instance using instead? Can you share the full log output?

This seems like the n8n application database connection is working fine. You should be able to see a bunch of n8n-created tables in the database already.

The warning appears to be related to the connection test for a Postgres node you’re using. I think this might have been caused by a bug which has been fixed in the meantime. If you’re having trouble using the Postgres node inside n8n, could you try running an updated version of n8n? For example by running n8nio/n8n:0.209.0 instead of just n8nio/n8n

Also make sure you update the hostname in the Postgresql credentials used by your nodes as well.

After n8n is started, using postgres in the UI will still prompt me that I cannot connect.

It seems you are still using localhost as a hostname in your credentials. As suggested above you need to change this to host.docker.internal, just like you did with the environment variable.

After trying the problem, the connection is still the same.


Can you try upgrading to the latest version of n8n as suggested above (using n8nio/n8n:0.209.0 instead of just n8nio/n8n in your docker run command)?

After upgrading the version, the password is wrong, and I can’t go to the UI page.


So this would suggest your credentials are wrong, just like the error message says.

You might want to simply delete your ~/.n8n folder if you don’t have any production data in n8n yet (as per this topic you’ve opened) and also clean the database you’re currently using, seeing you are using Postgres here rather than the SQLite database from your other thread. This would give you a fresh start.

Depending on which Windows version your are using and how your system is set up the ~/.n8n folder might live inside your WSL filesystem.

Alternatively you could use the CLI command to reset your credentials but this would have to be executed inside your docker container as documented here.

Going forward if you’re using n8n locally and are the only one using it you might want to skip setting a username & password, especially if you run several n8n instances using different databases rather then setting different credentials.

Hello sir, I have connected to my database, but what should I do to design my own node?

Why can’t the programming environment n8n built by myself be started?
Error:n8n’s port 5678 is already in use. Do you have another instance of n8n running already?