Looking to install n8n in Docker with auto-restart and persistent storage? You’re in the right place. Whether you're a beginner just diving into workflow automation or an intermediate user setting up a more reliable production environment, using Docker to run n8n ensures a clean, scalable, and easily maintainable setup.
In this guide, we’ll walk through how to install n8n in Docker the right way—making sure your data sticks around and the service starts automatically even after a system reboot. Let’s dive in!
Why Use Docker to Run n8n?
Docker simplifies the deployment of applications by packaging everything needed into a lightweight container. When you install n8n in Docker, you benefit from:
- Environment consistency across different machines and stages
- Simple upgrades and rollbacks
- Isolation from host configuration conflicts
- Easy automation during deployment
Now let’s get started with installing n8n in Docker while keeping your data persistent and the container set to auto-restart.
Prerequisites
Before you begin, make sure you have:
- A Linux server (Ubuntu/Debian, etc.) or macOS with Docker and Docker Compose installed
- Basic understanding of terminal commands
- A domain name (optional, but helpful if you want HTTPS access)
Step 1: Create a Docker Volume for Persistence
By default, containerized apps like n8n store their data inside ephemeral containers. To keep your workflows and credentials safe, you should mount a persistent volume.
Create a volume for n8n data
docker volume create n8n_data
This Docker-managed volume will store your workflows, credentials, and related data even if the container is rebuilt or stopped.
Step 2: Create a Docker Compose File
Using Docker Compose simplifies the configuration, especially when specifying environment variables, ports, and volumes.
Create a docker-compose.yml
file
In your project folder, create a new docker-compose.yml
file and insert the following:
version: "3.8"
services:
n8n:
image: n8nio/n8n
restart: always
ports:
- "5678:5678"
environment:
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=yourSecurePassword
- N8N_HOST=localhost
- N8N_PORT=5678
- N8N_PROTOCOL=http
- TZ=UTC
- NODE_ENV=production
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:
external: true
What each config does:
restart: always
: Ensures the container restarts if it crashes, or during server rebootvolumes
: Mounts the persistent volume we created earlierenvironment
: Sets up authentication, port, timezone, and environment
🔐 Pro Tip: Always replace
yourSecurePassword
with a long and secure password.
Step 3: Launch n8n Using Docker Compose
Now that your configuration is ready, it’s time to run the container.
Start the container
docker-compose up -d
This command pulls the latest n8n image, starts the container in detached mode (-d
), and applies the settings from your docker-compose.yml
file.
Verify that n8n is running
After a few seconds, open a browser and go to:
http://localhost:5678
If you’re on a remote server, replace localhost
with your server’s IP address.
Log in using the basic auth credentials (admin
/ yourSecurePassword
) you defined earlier.
Step 4: Test Auto-Restart and Persistence
To test if everything works correctly:
Restart Docker or your system
sudo systemctl restart docker
or simply reboot your machine.
After rebooting, n8n should come back online automatically, and none of your workflows should be lost.
Validate persistence
- Stop the container:
docker-compose down
- Bring it back:
docker-compose up -d
- Revisit http://localhost:5678 and confirm your previous workflows are still there
Optional: Add a Reverse Proxy & HTTPS
If you plan to expose your n8n instance on the internet, a reverse proxy like Nginx is recommended for managing domains and enabling HTTPS.
You can use tools like NGINX Proxy Manager or manually configure Nginx and secure it with Let's Encrypt.
Summary Table: Key Docker Options Used
Here’s a quick overview of the main Docker options used in this setup:
Option | Purpose |
---|---|
restart: always |
Ensures automatic restart on failure/reboot |
volumes |
Enables persistent storage |
environment |
Sets credentials and config variables |
ports |
Maps internal port to host machine |
(Insert as a table in WordPress using Table Block for better formatting.)
Real-World Mini Use Case: Automating Invoice Reminders
Let’s say you’re running a small business and want to automate email reminders for unpaid invoices. With n8n installed in Docker:
- You can create a workflow that polls a Google Sheet every day
- Filters rows where "Payment Status" is "Pending"
- Sends personalized emails via Gmail or SMTP
Because you’ve set up persistence, this workflow will be saved even if the server goes down—and thanks to auto-restart, everything resumes automatically. 🚀
Tips for Going Further
- Use
.env
files to separate your environment variables - Connect n8n with external Postgres or Redis for more scalability
- Back up your
n8n_data
volume regularly usingdocker volume inspect
and manual backup scripts
FAQ
Can I upgrade to a newer n8n version later?
Absolutely. Just run:
docker-compose pull
docker-compose up -d
This pulls the latest image and restarts the container with your saved data.
Is this setup safe for production use?
It’s a solid start. For full production readiness:
- Use HTTPS with a reverse proxy
- Store secrets securely (e.g., environment managers or Docker secrets)
- Regularly back up volumes
What ports does n8n use by default?
n8n listens on port 5678
by default. You can change this in your docker-compose.yml
by modifying the ports
section.
Can I run multiple n8n instances?
Yes, but you’ll need:
- Unique port mappings
- Separate volumes for each instance
- Distinct environment variables
Or, better yet, consider using Docker Swarm or Kubernetes for scaling.
Do I need a database for n8n?
The default setup uses SQLite, which stores data in your persistent volume. For multiple users or heavy workloads, it’s recommended to use PostgreSQL by setting DB_TYPE
and related environment variables.
By following this guide, you’re all set to install n8n in Docker with auto-restart and persistence—ready to unleash powerful workflow automation on your terms.