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):
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?
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)?
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.
cat > ~/apps/n8n/docker-compose.yml << EOF
docker compose up -d
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).
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