Container data is not saved in volume

Hi.
I am running n8n container on my server.
This is my docker-compose.yml file :

version : '3.3'
services:
  n8n:
    image: n8nio/n8n
    container_name: n8n-app
    restart: always
    ports:
      - "5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=SOME_PASSWORD!
      - N8N_HOST=MY_DOMAIN
      - MODE_ENV=production
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=MY_DOMAIN
      - N8N_SECURE_COOKIE=false
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
      - N8N_RUNNERS_ENABLED=true
      - N8N_PROXY_HOPS=1
      - TZ=UTC+2
      - N8N_PUSH_BACKEND=sse
      - N8N_PUSH_BACKEND_WS=true 
      - N8N_PUSH_BACKEND_WS_RECONNECT_TIMEOUT=5000  
      - N8N_PUSH_BACKEND_WS_KEEP_ALIVE_INTERVAL=20000 
    volumes:
      - n8n_data:/home/node/.n8n  # Absolute path to ensure mounting
    user: "0:0"  # Force n8n to run as the correct user

volumes:
  n8n_data:
    external: true

the docker compose file is located at ~/n8n/ and under root:root ownership.
I have already set permissions for 777 and created ~/n8n/n8n_data/home sub folder

for some reason the data is not being saved on the folder, and whenever I updated the container, all data is being deleted.

What am I missing?

running using docker on 22.04.5 LTS (Jammy Jellyfish)

When you use volumes: n8n_data with external: true in your docker-compose.yml, Docker manages the n8n_data volume outside your filesystem, typically in /var/lib/docker/volumes/. This keeps it separate from your local folders, and you don’t control its location directly. You need to create it first with docker volume create n8n_data, or Docker won’t know where to store the data, which might cause your issue.

If you’d rather store the data in your own filesystem (e.g., ~/n8n/n8n_data), you need these changes:

  1. Replace the volume line: - n8n_data:/home/node/.n8n with - /home/user/n8n/n8n_data:/home/node/.n8n.
  2. Remove the volumes section at the end (no external: true needed).
  3. Create the folder: mkdir -p ~/n8n/n8n_data.
  4. Set permissions: sudo chown root:root ~/n8n/n8n_data and sudo chmod 755 ~/n8n/n8n_data.

Then restart with docker-compose up -d. This keeps the data in your chosen folder instead of Docker’s managed space.

1 Like

If I set volume line to /home/user/n8n/n8n_data:/home/node/.n8n, why should I create the folder under root (mkdir -p ~/n8n/n8n_data)?

1 Like

The home directory /home/user will be /root in case you are running the docker under the root user