Setting up n8n on Raspberry Pi. Able to access localhost, but not from an ip address

I would like to set up n8n using Docker from my Raspberry Pi.

It works when I visit http://127.0.0.1:5678 (from Raspberry Pi)

However, it prompted error when I visit http://192.168.155.2:5678 (from Raspberry Pi)

I followed instructions - n8n-hosting/docker-compose/withPostgres at main · n8n-io/n8n-hosting · GitHub

Here is my docker compose file

version: '3.8'

volumes:
  db_storage:
  n8n_storage:

services:
  postgres:
    image: postgres:16
    restart: always
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - db_storage:/var/lib/postgresql/data
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
    ports:
      - 5678:5678
    links:
      - postgres
    volumes:
      - n8n_storage:/home/node/.n8n
    depends_on:
      postgres:
        condition: service_healthy

I also turned off the firewall from my Raspberry Pi 5 and the result still the same.

Could someone able to provide me some advice? Many thanks!

Docker ports mapping in theory should be good only the n8n ports.

But what about n8n env variables.

N8N_HOST=0.0.0.0 or N8N_HOST=

N8N_LISTEN_ADDRESS=0.0.0.0

Later it may be useful WEBHOOK_URL as well, if you don’t use proxy .

Last time I exposed my Raspberry Pi on the internet – there were a lot of hackers trying to hack into it every day. Maybe don’t turn off your firewall. :slight_smile:

Thanks @Parintele_Damaskin and @AlexS1 for your input.

I had already tried n8n host, web hook url, listen address , and the result still the same…

Now it finally work by using Cloudflare Tunnels… I just feel a bit wired… it should also work on the machine IP address…..