How to run n8n in Docker: install, Docker Compose self-hosting, and safe updates

How to run n8n in Docker: whether you should, install and start commands, self-hosting with Docker Compose, a first workflow, and updating without losing data.

On the mic
On the mic

Key takeaways

  • Run n8n in Docker with a named volume for /home/node/.n8n so workflows and credentials persist.
  • Docker is the recommended way to self-host n8n; use Docker Compose with PostgreSQL and HTTPS for production.
  • Set and back up N8N_ENCRYPTION_KEY; without it, saved credentials cannot be decrypted after a rebuild.
  • Update by pulling the new image and recreating the container; data lives in volumes, not the container.
  • Read breaking changes and back up before major version upgrades.

To run n8n in Docker, create a volume for its data, then start the official image with port 5678 published and the volume mounted at /home/node/.n8n; the editor opens at localhost:5678. For production, use Docker Compose with PostgreSQL, HTTPS and a fixed encryption key. Docker is part of my everyday deployment stack, so this page covers whether to use Docker for n8n, installing and starting it, self-hosting with Compose, a first workflow, and updating and upgrading without losing data.

How do I run n8n with Docker?

Create a named volume, then run the official n8n image with the port and volume mapped. Open the editor in your browser at port 5678 and create the owner account.

Also asked as: how to n8n docker · tutorial n8n docker · how to upgrade n8n docker

docker volume create n8n_data
docker run -it --rm --name n8n -p 5678:5678 \
  -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n

The volume stores the SQLite database, settings and encryption key, so workflows survive when the container is removed. The --rm flag deletes the container on stop, which is fine because data lives in the volume. For anything long-running, use -d instead of -it --rm, set a timezone with GENERIC_TIMEZONE, and move to Docker Compose.

Should I run n8n in Docker?

Yes, for most self-hosters. Docker is n8n's recommended self-hosting method: it isolates dependencies, makes updates a matter of pulling a new image, and keeps setups reproducible across laptops and servers.

Alternatives are n8n Cloud, which removes server management entirely, or installing with npm, which suits quick local experiments but makes upgrades and isolation harder. Docker is the better choice when you want control over data, need to run on your own server or a VPS, or plan to add PostgreSQL, a reverse proxy and backups. The trade-off is that you own security patches, monitoring and backups, so budget time for operations.

How do I install n8n with Docker?

Install Docker Desktop on Windows or macOS, or Docker Engine on Linux, then pull the official image with docker pull docker.n8n.io/n8nio/n8n and run it with a data volume. No separate n8n installation is needed; the image contains everything.

Also asked as: how to install n8n docker

Checklist:

  • Install Docker and confirm with docker --version.
  • Create a volume: docker volume create n8n_data.
  • Run the container with -p 5678:5678 and the volume mounted.
  • Open the editor and create the owner account.
  • Set N8N_ENCRYPTION_KEY explicitly and store it in a password manager.

On a server, also configure a domain, HTTPS and WEBHOOK_URL so webhooks receive the correct public address.

How do I start n8n in Docker?

Start it with docker run the first time, or docker start n8n for an existing stopped container. With Docker Compose, run docker compose up -d in the folder containing your compose file.

Also asked as: how to start n8n docker

Check it is running with docker ps, and read logs with docker logs -f n8n or docker compose logs -f. If the editor does not load, confirm the port mapping, that nothing else uses port 5678, and that a firewall allows it on servers. To start automatically after reboots, add --restart unless-stopped to docker run, or restart: unless-stopped in the compose file. Stop it cleanly with docker stop n8n or docker compose down.

How do I self-host n8n with Docker Compose?

Write a compose file with an n8n service, a PostgreSQL service and named volumes, add environment variables for host, protocol, webhook URL, timezone and encryption key, and put a reverse proxy such as Traefik or Caddy in front for HTTPS.

Also asked as: how to self-host n8n with docker compose

Key settings:

  • DB_TYPE=postgresdb with PostgreSQL host, user, password and database variables.
  • N8N_HOST, N8N_PROTOCOL=https and WEBHOOK_URL for your domain.
  • N8N_ENCRYPTION_KEY, kept in an .env file excluded from git.
  • Volumes for n8n data and PostgreSQL data.
  • restart: unless-stopped on every service.

n8n's documentation provides a complete Docker Compose example with Traefik and automatic certificates. Back up the PostgreSQL database and .env file regularly.

What is a simple n8n Docker tutorial for a first workflow?

After starting n8n in Docker, open the editor, create a workflow with a Schedule or Webhook trigger, add an action node such as HTTP Request or Gmail, test it, and activate it. Webhooks need a URL reachable from the internet.

A first workflow to try: a Schedule trigger every morning, an HTTP Request node that fetches data from an API, a Set or Code node that formats it, and a node that sends the result to email, Slack or Telegram. Add credentials through the editor; they are encrypted with your encryption key. Use executions history to debug each run. Export important workflows as JSON and keep them in version control.

How do I update n8n in Docker?

Pull the newer image, then recreate the container with the same volume and settings. Your workflows and credentials stay in the volume or database, so replacing the container does not delete them.

Also asked as: how to update n8n docker

For a docker run setup:

docker pull docker.n8n.io/n8nio/n8n
docker stop n8n && docker rm n8n
docker run -d --name n8n -p 5678:5678 \
  -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n

Prefer pinning a specific version tag rather than latest, so updates happen when you choose. Read the release notes before updating, and test on a staging copy if workflows are business-critical.

How do I update n8n in Docker without losing data?

Keep all data in named volumes or an external PostgreSQL database, back them up before updating, keep the same N8N_ENCRYPTION_KEY, and recreate only the container. Data loss usually comes from missing volumes or a changed encryption key.

Also asked as: how to update n8n docker without losing data

Safety checklist:

  • Confirm /home/node/.n8n is mounted to a named volume or host folder.
  • Back up the volume, or run pg_dump for PostgreSQL.
  • Export workflows and credentials with the n8n CLI as an extra copy.
  • Keep the .env file and encryption key unchanged.
  • Never run docker volume rm or docker compose down -v during updates.

After updating, open a few workflows and check recent executions to confirm everything works.

How do I update n8n with Docker Compose?

In the folder with your compose file, run docker compose pull to fetch new images, then docker compose up -d to recreate changed containers. Data in named volumes is preserved.

Also asked as: how to update n8n docker compose

If your compose file pins a version tag, edit the tag first, then pull and start. Watch logs with docker compose logs -f n8n while database migrations run on startup, and do not interrupt them. Remove old images later with docker image prune to save disk space. If something breaks, change the tag back to the previous version and restore your database backup, since migrations may not be reversible.

How do I upgrade n8n across major versions in Docker?

Read n8n's breaking changes notes for every version between yours and the target, back up the database and encryption key, then upgrade by changing the image tag. Major releases such as 1.0 changed defaults and removed deprecated features.

For large jumps, upgrade in steps rather than all at once, checking workflows after each. Test on a staging copy with a restored backup if possible. Look for deprecated nodes, changed environment variables and new requirements, such as database version support. After upgrading, review workflows that use Code nodes or community nodes, which are most often affected, and keep the backup until you have confirmed everything runs correctly for a few days.

Sources

  1. n8n Docs, Docker installationdocs.n8n.io
  2. n8n Docs, Docker Compose server setupdocs.n8n.io
  3. n8n Docs, Hosting n8ndocs.n8n.io
  4. n8n, repositorygithub.com
  5. Docker Docs, Volumesdocs.docker.com
Pranjul Rathour
Pranjul Rathour
GenAI Engineer · India

GenAI engineer and AI product builder with 2+ years shipping production-grade AI systems: RAG pipelines, fine-tuned LLMs, hybrid retrieval and multi-modal apps across vision, speech and OCR, architected end to end from ingestion to deployment. Leads engineering for SCULT INDIA's 14-member team, founded the 500+ member TechVerse Enclave community and has mentored 200+ students. Three hackathon first prizes: Changethon 2025 (IIT Roorkee), Product Genesis at Vividhotsava 2025 (CSJMU) and BYTEBATTLE (MeetKats).

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way. Email pranjulrathour41@gmail.com.

Keep reading

More on Shipping AI apps

All Shipping AI apps guides →
Campus talks · hackathon judging · mentoring

Want this as a live session at your college?

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way.

Pranjul Rathour, GenAI engineer in India