Upgrading n8n in Docker Without Losing Data
This guide explains how to upgrade n8n running in Docker to the latest version, while preserving your workflows and credentials.
Important: Replace n8n.example.com in the commands with your own domain or subdomain.
Step 0: Optional — Run Docker Without sudo
By default, Docker requires sudo for every command. To avoid this, add your user to the Docker group:
sudo usermod -aG docker $USERLog out and log back in for the changes to take effect. After this, you can run docker commands without sudo.
Step 1: Stop and Remove the Old Container
docker stop n8n
docker rm n8nStep 2: Remove All Unused Images and Layers
This will delete all unused Docker images, including old n8n layers.
docker image prune -aTo also clear unused networks and build cache, run:
docker system prune -afNote: This does not remove volumes, so your data volume will remain intact.
Step 3: Confirm the Data Volume Exists
List all volumes:
docker volume lsYou should see an entry like:
local n8n_dataFor more details, inspect the volume:
docker volume inspect n8n_dataStep 4: Run the New Container with Your Existing Volume
Start a new container that uses the existing data volume:
docker run -d --name n8n \
--restart=always \
-p 5678:5678 \
-v n8n_data:/home/node/.n8n \
-e N8N_HOST=0.0.0.0 \
-e N8N_PORT=5678 \
-e WEBHOOK_URL=https://n8n.example.com/ \
-e VUE_APP_URL_BASE_API=https://n8n.example.com/ \
docker.n8n.io/n8nio/n8n:latestIf the image is not available locally, Docker will download the latest version before creating the container.
Remember to replace n8n.example.com with your actual domain or subdomain.
Step 5: Verify the Upgrade
Check the container logs:
docker logs -f n8nThen open your browser and visit:
https://n8n.example.com/Your workflows and credentials should still be available.