How to upgrade n8n with docker-compose setup?

@Jon , hi.
Check out my docker-compose file.
I’m losing all the data when I upgrade.

version: "3"

services:
  traefik:
    image: "traefik"
    restart: always
    command:
      - "--api=true"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
      - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
      - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
    ports:
      - "443:443"
    volumes:
      - ${DATA_FOLDER}/letsencrypt:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro
 
  n8n:
    image: n8nio/n8n
    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=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
    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_TUNNEL_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - ${DATA_FOLDER}/.n8n/local-files:/files
      - ${DATA_FOLDER}/.n8n:/root/.n8n
   

Hey @IndieDev,

${DATA_FOLDER}/.n8n:/root/.n8n This should be ${DATA_FOLDER}/.n8n:/home/node/.n8n but it depends on what the DATA_FOLDER env option is set to so you might need to double check that. If you were running the compose up command as root you may have a different result than if you were running it as a user called indiedev so it is worth checking your user account as well.

There are some other env options that need to be updated as well so it would be worth reviewing the documentation as a starting point the basic auth options don’t exist anymore and webhook_tunnel_url is now just webhook_url

DATA_FOLDER=/root/n8n/
in the env folder I have it set to the following value

Perfect that should be ok then, try updating the volume as suggested and as long as you have not overwritten it you should be good to go

1 Like

@Jon , thank you very much. Everything updated to the latest version. The data is still intact.

1 Like

Hi!

After these steps I got 502 Bad Gateway error. What could be the problem?

Best to check what the containers output. I assume there you will find some errors that help you to debug the issue.

Hello all.
I followed this thread to update n8n on Digital Ocean to the latest version. Everything seems to have worked but logging into the app, it says I’m still on the previous version (Yes I have logged out and back in twice)

Can anyone point out where I’ve gone wrong? Appreciate it

root@n8n:~# docker pull n8nio/n8n
Using default tag: latest
latest: Pulling from n8nio/n8n
4abcf2066143: Pull complete 
e7ced292c644: Pull complete 
b32c0114bba5: Pull complete 
f3748d9674b0: Pull complete 
a981675a3a21: Pull complete 
2dc19a753eca: Pull complete 
4f4fb700ef54: Pull complete 
bd324e61ea9f: Pull complete 
ecf62981380b: Pull complete 
bdf65bb66815: Pull complete 
Digest: sha256:efebfc3b819e155ea184030fbaec05184412cca22d775ed2c479f0432e38b54a
Status: Downloaded newer image for n8nio/n8n:latest
docker.io/n8nio/n8n:latest
root@n8n:~# find . -name *.yml
./n8n-docker-caddy/docker-compose.yml
root@n8n:~# cd n8n-docker-caddy
root@n8n:~/n8n-docker-caddy# docker compose down
[+] Running 3/3
 ✔ Container n8n-docker-caddy-caddy-1  Removed                                                              0.4s 
 ✔ Container n8n-docker-caddy-n8n-1    Removed                                                              0.7s 
 ✔ Network n8n-docker-caddy_default    Removed                                                              0.0s 
root@n8n:~/n8n-docker-caddy# docker compose up -d
[+] Running 3/3
 ✔ Network n8n-docker-caddy_default    Created                                                              0.1s 
 ✔ Container n8n-docker-caddy-n8n-1    Started                                                              0.8s 
 ✔ Container n8n-docker-caddy-caddy-1  Started                                                              0.8s 

Hey @inez,

Welcome to the community :cake:

What version are you running and what version are you expecting it to be? Is your compose file also using n8nio/n8n:latest as the image or is it using docker.n8n.io/n8nio/n8n?

Hi guys, I’m new to the forum and thank everyone for their commitment to the fantastic opensource software n8n. I have created a bash script for my digital ocean droplet and have the following issue:
when i run the bashscript everything is updated correctly via docker compose but after the update i don’t have access to my credentials for different nodes anymore. is it possible to fix this issue?
Attached is the bash script:
#!/bin/bash

Navigate to the directory of your Docker Compose setup

Stop the n8n service

docker compose stop n8n

Get the latest n8n image version

docker compose pull n8n

Update the n8n version in the Docker Compose file

sed -i ‘s/n8nio/n8n:.*/n8nio/n8n:latest/’ docker-compose.yml

Start the updated services

docker compose up --force-recreate -d

echo “n8n service has been successfully updated.”
many thanks in advance for your help and best regards

C.

Hey @chooomedia,

Welcome to the community :cake:

If you are missing credentials or can’t access them it would suggest that the docker volume is not being set in your compose file correctly. When you say you don’t have access what does that actually mean, Are they there but they fail to load with an error or do you need to do the full setup again?

With your bash script you can also get away with just having the below which should do the job assuming your compose file is already set to use n8n:latest for the image name.

#!/bin/bash
docker compose pull
docker compose stop
docker compose up -d

Hi Jon,

Thank you very much for your quick reply. The credentials for the nodes are still displayed, but I can neither see the credentials nor use them in the corresponding nodes after an update. I could now update the n8n instance to give you the correct error code, but then I would have to create all the credentials again.

Thank you in advance,
C.

That is not an issue I have seen before, if they are displayed they should be usable. What happens if you try to open them and did you try clearing the browser cache?

Thanks for your answer - here my docker-compose.yml:

services:
postgres:
image: postgres:16.1
restart: unless-stopped
environment:
POSTGRES_PASSWORD: PASS
volumes:
- ./data/postgres:/var/lib/postgres
networks:
- n8n_network

n8n:
image: n8nio/n8n:latest
restart: unless-stopped
ports:
- 5678:5678
user: USER
environment:
DB_TYPE: postgresdb
DB_POSTGRESDB_DATABASE: POSTGRESSDB
DB_POSTGRESDB_HOST: POSTGRESSDB
DB_POSTGRESDB_PORT: 5432
DB_POSTGRESDB_USER: POSTGRESSUSR
DB_POSTGRESDB_PASSWORD: PASS
N8N_BASIC_AUTH_ACTIVE: true
N8N_BASIC_AUTH_USER: EMAIL
N8N_BASIC_AUTH_PASSWORD: PASSAUTH
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/n8n/n8n:/home/node/.n8n
- ./data/n8n/files:/files
networks:
- n8n_network
depends_on:
- postgres

Thanks for your answer look these:

Anyone has a Solution for my Issue?