Unable to import workflows/credentials when running n8n w/ docker

I was previously using n8n via npm, but recently switched over to Docker. Previously, I had no issues importing my workflows/credentials via CLI, but that’s no longer working for me. I’m using the exact same files that I had successfully imported before.

I have a really simple docker-compose file (just using it for testing purposes right now):

version: "3"

services:
  n8n:
    image: n8nio/n8n
    ports:
      - 8003:5678
    volumes:
      - /home/adam/n8n/data/:/home/node/.n8n
    restart: always

I had previously exported like this:

n8n export:workflow --all --output=workflows.json
n8n export:credentials --all --decrypted --output=credentials.json

Now I’m trying to import like this:

docker cp ~/workflows.json n8n-n8n-1:/data/
docker cp ~/credentials.json n8n-n8n-1:/data/

docker exec -it n8n-n8n-1 n8n import:workflow --input=workflows.json
docker exec -it n8n-n8n-1 n8n import:credentials --input=credentials.json

From that, I get:

Successfully imported 2 workflows.
Successfully imported 1 credential.

However, when I refresh my n8n page, there aren’t any workflows or credentials present.

I’m not super familiar with docker, so I assume the way I’m importing in the container is wrong. What’s the correct method for importing when running n8n in a docker container?

1 Like

Hey @adamhl8, welcome to the community!

I did run the CLI commands inside docker containers in the past, without much of a problem tbh. I’ve even tested the commands you have used just now and a previously exported workflow was imported fine for me. So I am a bit puzzled as to what might have gone wrong here.

This might sound stupid, but is there any chance you are looking at the wrong n8n instance in your browser (something like http://localhost:5678 instead of http://localhost:8003 which would be where your docker container listens)?

1 Like

I double-checked that I only have one n8n instance running. I also just completely wiped my VPS and started from scratch, and I’m still running into the same issue. I have a bash script that I use to bootstrap n8n. It’s pretty much the same as what I wrote above, but here it is so you can see exactly what I’m doing.

#!/bin/bash

mkdir ~/apps/n8n/

cat > ~/apps/n8n/docker-compose.yml << EOF
version: "3"

services:
  n8n:
    image: n8nio/n8n
    container_name: n8n
    network_mode: "host"
    volumes:
      - /home/adam/apps/n8n/data/:/home/node/.n8n/
    environment:
      - N8N_LISTEN_ADDRESS=127.0.0.1
      - N8N_PORT=8003
      - WEBHOOK_URL=https://${domain}
    restart: always
EOF

cd ~/apps/n8n/
docker compose up -d
cd ~/

# Import
docker cp ~/workflows.json n8n:/data/
docker cp ~/credentials.json n8n:/data/

docker exec -it n8n n8n import:workflow --input=workflows.json
docker exec -it n8n n8n import:credentials --input=credentials.json

I’m serving n8n via a caddy reverse proxy, but that shouldn’t have anything to do with this issue (I think).

n8n.${domain} {
  reverse_proxy localhost:8003
}

Ah, figured it out.

The problem is that when you enter a shell in the container (or run a command like I am), it’s being done as root. Most of the n8n stuff in the container is owned by the user node. There’s some weird permission stuff going on I guess. If I run the import commands as node, my workflows and credentials show up in n8n.

docker exec -it -u node n8n n8n import:workflow --input=workflows.json
docker exec -it -u node n8n n8n import:credentials --input=credentials.json
5 Likes