N8n data not persisting after Update to 1 (docker compose)

Describe the problem/error/question

Docker Compose pull/update causes loss of data after versions 1.1

docker-compose pull
docker-compose down
docker-compose up -d

I can’t see anything in the migration guides - am i missing changes in docker-compose.yml?

Information on your n8n setup

  • n8n version: 1.1.1
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via Docker Compose:
  • Operating system: Ubuntu

Can you please share your docker-compose file. That will allow us to help you with that problem. Thanks!

1 Like

docker-compose.yml

version: "3"

services:
  traefik:
    image: "traefik"
    user: root
    restart: always
    command:
      - "--api=true"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
      - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
      - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ${DATA_FOLDER}/letsencrypt:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro

  n8n:
    image: n8nio/n8n
    user: root
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n.tls=true
      - traefik.http.routers.n8n.entrypoints=web,websecure
      - traefik.http.routers.n8n.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
      - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n.headers.STSPreload=true
      - traefik.http.routers.n8n.middlewares=n8n@docker
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - ${DATA_FOLDER}/.n8n:/home/node/.n8n
      - /local-files:/files

.env

# Folder where data should be saved
DATA_FOLDER=/root/n8n/

# The top level domain to serve from
DOMAIN_NAME=*********.co.uk

# The subdomain to serve from
SUBDOMAIN=node4

# DOMAIN_NAME and SUBDOMAIN combined decide where n8n will be reachable from
# above example would result in: https://n8n.example.com

# The user name to use for authentication - IMPORTANT ALWAYS CHANGE!
N8N_BASIC_AUTH_USER=****

# The password to use for authentication - IMPORTANT ALWAYS CHANGE!
N8N_BASIC_AUTH_PASSWORD=****

# Optional timezone to set which gets used by Cron-Node by default
# If not set New York time will be used
GENERIC_TIMEZONE=Europe/London

# The email address to use for the SSL certificate creation
SSL_EMAIL=****@biketrax.co.uk

N8N_DEFAULT_BINARY_DATA_MODE=filesystem

EXECUTIONS_DATA_PRUNE=true

EXECUTIONS_DATA_MAX_AGE=48

DB_SQLITE_VACUUM_ON_STARTUP=true

# Set the logging level to 'debug'
export N8N_LOG_LEVEL=debug

# Set log output to both console and a log file
export N8N_LOG_OUTPUT=console,file

# Set a save location for the log file
export N8N_LOG_FILE_LOCATION=/home/logs/n8n.log

# Set a 50 MB maximum size for each log file
export N8N_LOG_FILE_MAXSIZE=50

# Set 60 as the maximum number of log files to be kept
export N8N_LOG_FILE_MAXCOUNT=60

Hey @Luke_Austin,

It is probably the data folder and the root user being set in the config, We changed from using the root user in the container to the node user instead.

Try removing the user from your n8n config then running the command below to see if it helps

docker run --rm -it --user root -v /root/n8n/.n8n:/home/node/.n8n --entrypoint chown n8nio/base:16 -R node:node /home/node/.n8n

It might be worth cleaning up some of the other environment options that are not used anymore as well like basic auth.

2 Likes

argh…

So, now i’ve got:

version: "3"

services:
  traefik:
    image: "traefik"
    user: root
    restart: always
    command:
      - "--api=true"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
      - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
      - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ${DATA_FOLDER}/letsencrypt:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro

  n8n:
    image: n8nio/n8n
#    user: root
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n.tls=true
      - traefik.http.routers.n8n.entrypoints=web,websecure
      - traefik.http.routers.n8n.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
      - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n.headers.STSPreload=true
      - traefik.http.routers.n8n.middlewares=n8n@docker
    environment:
 #     - N8N_BASIC_AUTH_ACTIVE=true
 #     - N8N_BASIC_AUTH_USER
 #     - N8N_BASIC_AUTH_PASSWORD
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
 #    - ${DATA_FOLDER}/.n8n:/home/node/.n8n

# Folder where data should be saved
#DATA_FOLDER=/root/n8n/

# The top level domain to serve from
DOMAIN_NAME=***********

# The subdomain to serve from
SUBDOMAIN=node4

# DOMAIN_NAME and SUBDOMAIN combined decide where n8n will be reachable from
# above example would result in: https://n8n.example.com

# The user name to use for authentication - IMPORTANT ALWAYS CHANGE!
#N8N_BASIC_AUTH_USER=

# The password to use for authentication - IMPORTANT ALWAYS CHANGE!
#N8N_BASIC_AUTH_PASSWORD=

# Optional timezone to set which gets used by Cron-Node by default
# If not set New York time will be used
GENERIC_TIMEZONE=Europe/London

# The email address to use for the SSL certificate creation
[email protected]

N8N_DEFAULT_BINARY_DATA_MODE=filesystem

EXECUTIONS_DATA_PRUNE=true

EXECUTIONS_DATA_MAX_AGE=48

DB_SQLITE_VACUUM_ON_STARTUP=true

# Set the logging level to 'debug'
export N8N_LOG_LEVEL=debug

# Set log output to both console and a log file
export N8N_LOG_OUTPUT=console,file

# Set a save location for the log file
export N8N_LOG_FILE_LOCATION=/home/logs/n8n.log

# Set a 50 MB maximum size for each log file
export N8N_LOG_FILE_MAXSIZE=50

# Set 60 as the maximum number of log files to be kept
export N8N_LOG_FILE_MAXCOUNT=60

Am i still missing something?

Hey @Luke_Austin,

Were you using the User Management feature before? If this is the first time you would have to make an account. Are you also running as root on the server or as a different user?

I just had a single user, but yeah I had set up a user account for me since you introduced that feature a while back.

I’m running docker-compose non-root, but there was some wierdness with permissions to get local file storage working, so I’m not quite sure how I ended up there!

I’m getting a couple of warnings in my batch script now (ignore the postgres one - I tried hookign up to a local postgres instance to get passed the database wipe, but abandoned it - just haven;t pruned the container yet):

luke@node4:~$ ./n8nupdate.sh
WARNING: The DATA_FOLDER variable is not set. Defaulting to a blank string.
Pulling traefik ... done
Pulling n8n     ... done
WARNING: The DATA_FOLDER variable is not set. Defaulting to a blank string.
Stopping n8n-docker_traefik_1 ... done
Stopping n8n-docker_n8n_1     ... done
WARNING: Found orphan containers (n8n-docker_postgres_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Removing n8n-docker_traefik_1 ... done
Removing n8n-docker_n8n_1     ... done
Removing network n8n-docker_default
ERROR: error while removing network: network n8n-docker_default id 43e33996e89f76b791e39cd345d7a0d9b11fe9609a6c2261ed834445d6e5f62a has active endpoints
WARNING: The DATA_FOLDER variable is not set. Defaulting to a blank string.
WARNING: Found orphan containers (n8n-docker_postgres_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Creating n8n-docker_traefik_1 ... done
Creating n8n-docker_n8n_1     ... done

Luke

Hey @Luke_Austin,

You have commented out the Data_folder env option, You can keep that as /root/n8n/ as it has your info in it unless you move it to another OS users accounts assuming non root in which case the path will need to be updated.

Thanks @Jon that clears the error, but data still doesn’t persist.

TBH i’ve got all the workflows backed up to github, so rebuilding stuff isn’t too bad.

Is there a working .env / docker-compose.yml template? I can just start from scratch… I’ve been considering building a bramble cluster for our automations anyway…

1 Like

@Luke_Austin I am a fan of this one: GitHub - n8n-io/n8n-docker-caddy: Get up and running with n8n on DigitalOcean

Thanks @Jon - I’m trying that (not on digital ocean, ut the instructions are easy enough to adapt).

#offtopic

I’ve nto used Caddy before, and i’m getting a HTTP 502 error, this is in the caddy log:

{"level":"error","ts":1691489982.5435536,"logger":"http.log.error","msg":"dial tcp 172.19.0.2:5678: connect: connection refused","request":{"remote_ip":"***.***.**.**","remote_port":"54204","client_ip":"***.***.**.**","proto":"HTTP/2.0","method":"GET","host":"****.****.co.uk","uri":"/","headers":{"Sec-Ch-Ua-Platform":["\"Windows\""],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"],"Sec-Fetch-Mode":["navigate"],"Sec-Ch-Ua-Mobile":["?0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Accept-Language":["en-GB,en-US;q=0.9,en;q=0.8"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Sec-Fetch-Dest":["document"],"Cookie":[],"Sec-Ch-Ua":["\"Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"115\", \"Chromium\";v=\"115\""],"Sec-Purpose":["prefetch;prerender"],"Purpose":["prefetch"],"Accept-Encoding":["gzip, deflate, br"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"***.****.co.uk"}},"duration":0.000999196,"status":502,"err_id":"rppyxr4cp","err_trace":"reverseproxy.statusError (reverseproxy.go:1246)"}

Do you have any tips? The only bit that makes no sense to me is that 172.19.0.2 IP - surely that should be localhost or the local ip?

Luke

Hey @Luke_Austin,

172.190.02 is likely to be the IP for the Docker network, It could be that n8n is not listening on that port although it should be working. If you check the docker logs has n8n started up ok?

Ah that’s it - still a permission error:

Error: EACCES: permission denied, open '/home/node/.n8n/crash.journal'
Error: Exiting due to an error.

Hey @Luke_Austin,

Try running the command now making sure that /root/n8n/.n8n is the correct path to your data and you should be good to go.

docker run --rm -it --user root -v /root/n8n/.n8n:/home/node/.n8n --entrypoint chown n8nio/base:16 -R node:node /home/node/.n8n
1 Like

So, following the user guide, here:

and having created a user “n8n” - that should be:

docker run --rm -it --user root -v /home/n8n/n8n-docker-caddy/.n8n:/home/node/.n8n --entrypoint chown n8nio/base:16 -R node:node /home/node/.n8n

That gives me a permission denied, and running it with sudo sorts the issue.

I’ll drop the git repo maintainer a line to ask for that to be added to the howto!

Luke

3 Likes

That would be me :joy:

In theory it shouldn’t be needed so I have been trying to look into how we can fix that properly.

3 Likes

Thats why you were fond of that howto then… :joy:

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.