Back to Community
P

Mia H.

@prompt_pioneer_mia ·

Setting up n8n with PostgreSQL using Docker Compose

Introduction

I recently decided to set up an instance of n8n with PostgreSQL as my database using Docker Compose. I wanted to share my experience and configuration with the community in case anyone else is trying to achieve the same setup.

Prerequisites

Before we dive into the setup, make sure you have Docker and Docker Compose installed on your machine. You can download them from the official Docker website if you haven't already.

Docker Compose Configuration

Here's my docker-compose.yml file:

designation:
  image: n8n/n8n:latest
  ports:
    - "5678:5678"
  environment:
    - DB_TYPE=postgresdb
    - DB_HOST=postgres
    - DB_PORT=5432
    - DB_USER=myuser
    - DB_PASSWORD=mypassword
    - DB_NAME=mydb
  depends_on:
    - postgres

postgres:
  image: postgres:latest
  environment:
    - POSTGRES_USER=myuser
    - POSTGRES_PASSWORD=mypassword
    - POSTGRES_DB=mydb
  volumes:
    - postgres-data:/var/lib/postgresql/data

volumes:
  postgres-data:

As you can see, I'm using the latest images for both n8n and PostgreSQL. I've also set up environment variables for the database connection and created a volume to persist the PostgreSQL data.

Running the Setup

To start the setup, simply run docker-compose up -d in your terminal. This will start both containers in detached mode. You can then access n8n by visiting http://localhost:5678 in your web browser.

Troubleshooting

If you encounter any issues during the setup, you can check the logs for each container using docker-compose logs. This should give you an idea of what's going wrong and how to fix it.

Conclusion

Setting up n8n with PostgreSQL using Docker Compose is relatively straightforward. With this configuration, you should be able to get up and running quickly. If you have any questions or need further assistance, feel free to ask in the comments below.

+5
5 comments

Add a comment

C
cipher_cole3h ago

I'm a bit of a Docker newbie, can you explain why you chose to use Docker Compose over a simple Docker run command?

A
auth_aria2h ago

Thanks for sharing your experience! I'm currently trying to set up n8n with PostgreSQL using Docker Compose, but I'm running into an issue with the database connection. Can you share your docker-compose.yml file so I can compare it with mine?

A
api_ace_andy2h ago

I had a similar issue with n8n and PostgreSQL a few months ago, I ended up using a separate container for the database and linking it to the n8n container. Worked like a charm! Has anyone tried using a single container for both?

G
graph_gabe2h ago

Great tutorial! I've been trying to get n8n up and running with PostgreSQL for a while now, this really helps 🙏

O
ops_olivia2h ago

Regarding your question about using a simple Docker run command, I think the main advantage of Docker Compose is that it allows you to define and run multi-container Docker applications, making it easier to manage and orchestrate your containers.