Install n8n on Synology with docker

Hi!

I’m trying to install n8n on my DS218 with docker, with the existing docker-compose file from GitHub. I can get both docker container installed without errors, but after then the n8n container keeps restarting all the time. Here are my modified docker-compose and the error log:

Docker Compose

version: '3.1'

services:

  postgres:
    image: postgres:11
    restart: always
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh

  n8n:
    image: 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}
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
    ports:
      - 5678:5678
    links:
      - postgres
    volumes:
      - /volume1/docker/n8n:/home/node/.n8n
    # Wait 5 seconds to start n8n to make sure that PostgreSQL is ready
    # when n8n tries to connect to it
    command: /bin/sh -c "sleep 5; n8n start"

Error Log

|date|stream|content|
|---|---|---|
|2021-03-22 09:45:35|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 09:45:35|stderr| ›   Error: There was an error: Error parsing n8n-config file |
|2021-03-22 09:44:58|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 09:44:58|stderr| ›   Error: There was an error: Error parsing n8n-config file |
|2021-03-22 09:44:35|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 09:44:35|stderr| ›   Error: There was an error: Error parsing n8n-config file |
|2021-03-22 09:44:18|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 09:44:18|stderr| ›   Error: There was an error: Error parsing n8n-config file |
|2021-03-22 09:44:04|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 09:44:04|stderr| ›   Error: There was an error: Error parsing n8n-config file |
|2021-03-22 09:43:52|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 09:43:52|stderr| ›   Error: There was an error: Error parsing n8n-config file |
|2021-03-22 09:43:40|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 09:43:40|stderr| ›   Error: There was an error: Error parsing n8n-config file |
|2021-03-22 09:43:29|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 09:43:29|stderr| ›   Error: There was an error: Error parsing n8n-config file |
|2021-03-22 09:43:17|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 09:43:17|stderr| ›   Error: There was an error: Error parsing n8n-config file |
|2021-03-22 09:43:03|stdout|Stopping n8n...|
|2021-03-22 09:43:03|stdout||
|2021-03-22 09:43:03|stderr|There was an error initializing DB: connect ECONNREFUSED 172.18.0.3:5432|
|2021-03-22 09:43:03|stdout|UserSettings got generated and saved to: /home/node/.n8n/config|

Does anybody has a solution for this problem? Thank you!

Not sure I understand. The error message says very clear what the issue is:
/home/node/.n8n/config". It does not seem to be valid JSON.

Do you have a valid config-file at that location?

Hi Jan. Thanks for the quick response.

I thought this file will be created from n8n by the installation process. Where do I get this file or the file structure for this file? I can’t find this information on GitHub.

Ah yes, that file does get auto-generated on the first startup. But if it throws that error there must be a problem with that file. Some ideas:

  1. it got generated on the first start and it got then messed up in between (like for example got overwritten or because of a crash it did not write fully)
  2. there are some access right issues
  3. the file is a folder

I’ve installed the compose file like all the other compose files as “root-user” in the same docker subdirectory (/volume1/docker/n8n). n8n is creating the “config” file in the directory (/volume1/docker/n8n), but the file is empty! I also tried the compose file with PUID and PGID:

version: '3.1'

services:

  postgres:
    image: postgres:11
    restart: always
    environment:
      - PUID=1026
      - PGID=100
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh

  n8n:
    image: n8nio/n8n
    restart: always
    environment:
      - PUID=1026
      - PGID=100
      - 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}
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
    ports:
      - 5678:5678
    links:
      - postgres
    volumes:
      - /volume1/docker/n8n:/home/node/.n8n
    # Wait 5 seconds to start n8n to make sure that PostgreSQL is ready
    # when n8n tries to connect to it
    command: /bin/sh -c "sleep 5; n8n start"

Same logs:

|date|stream|content|
|---|---|---|
|2021-03-22 18:57:40|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 18:57:40|stderr| ›   Error: There was an error: Error parsing n8n-config file |
|2021-03-22 18:57:28|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 18:57:28|stderr| ›   Error: There was an error: Error parsing n8n-config file |
|2021-03-22 18:57:15|stdout|Stopping n8n...|
|2021-03-22 18:57:15|stdout||
|2021-03-22 18:57:15|stderr|There was an error initializing DB: getaddrinfo ENOTFOUND postgres|
|2021-03-22 18:57:15|stderr| ›   "/home/node/.n8n/config". It does not seem to be valid JSON.|
|2021-03-22 18:57:15|stderr| ›   Error: There was an error: Error parsing n8n-config file|

Hi @Jonathan_English!!
You can use my example.
The problems are related to volumes.

2 Likes

Hi @hermanmaleiane!

Thanks for your compose file. Unfortunately, I have the same errors with this one!
Are you sure about the volumes linkages?

Hi @Jonathan_English.
I’m 100% sure about that. I had this error and i have manage to fix.
You can try to comment that line and create the volume after that.

@hermanmaleiane
I’m not sure which volume line do you mean. Here my lastest compose file:

version: '3.1'

services:

  postgres:
    image: postgres:11
    container_name: n8n_postgres
    restart: always
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh

  n8n:
    image: n8nio/n8n
    container_name: 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}
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
    ports:
      - 5678:5678
    links:
      - postgres
    volumes:
      - n8n_data:/home/node/

volumes:
   n8n_data:

As i can see in your logs the first error was at (09:43:03.)
|2021-03-22 09:43:03|stderr|There was an error initializing DB: connect ECONNREFUSED 172.18.0.3:5432|

Run this on your CLI to allow access on the port 5432.

firewall-cmd --permanent --add-port=5432/tcp --zone=public
firewall-cmd --reload

and restart the container

@hermanmaleiane
I’m not sure how to execute this command. My time window is very short caused by the restart of the container all few seconds :face_with_raised_eyebrow:

Hi,
Just copy and paste into your Linux terminal.
It seems like your n8n is not able to connect to the database as I can see on your logs.
That command will enable that port to be listened on your firewall.

Good luck

It’s running. The problem ist related to the docker compose file, but I don’t know what the problem is. :grinning:

I installed postgres and then n8n manually and now it is running. :ok_hand:

Thanks for the help!

1 Like

Hi guys,

I’m trying to doing a docker install on my Synology too.
The errors that I see are somewhat similar:

Initializing n8n process
UserSettings got generated and saved to: /home/node/.n8n/config
› Error: There was an error: EACCES: permission denied, open
› ‘/home/node/.n8n/config’

I’ve set all the ENV variables for MySQL and I also set PUID and PGID, but somehow I still get these errors. It seems that it ignores the PUID and PGID, as the folder permissions are changed to ‘root’.

Here’s an attempt running from prompt:

docker run -it --rm --name n8n -p 5678:5678 -v /volume1/docker/n8n:/home/node/.n8n n8nio/n8n n8n start --tunnel
Initializing n8n process
UserSettings got generated and saved to: /home/node/.n8n/config
There was an error initializing DB: “SQLITE_CANTOPEN: unable to open database file”
Stopping n8n…

Any ideas?

Hey @Erwin, I have n8n running on Docker (behind a reverse proxy) using the latest official image from the registry.
Here’s a copy of my configuration; try replicating it and let me know if it fixes your issue!

Edit: Just took a second look, it could be that you don’t have write permissions enabled on the volume you used for the n8n container?

Hey @Jonathan_English, could you try adding this to your n8n service configuration in the compose file?
That should make sure that your database service is started before n8n; which may not have happened in your previous compose file; causing it to fail.

depends_on:
      - postgres

Do you used tthe docker-compose file or do you performed a manual installation?

Manual installation via the synology docker interface.

Thanks! Unfortunately no success. Do you use root or a specific user account for docker?

Just a normal administrator account; not root.

Have you checked to see if the docker user has read/write access on volume1 and the directory for the docker volume you’re mounting?