Ready to try-out n8n as your next automation platform? Or are you already a long time user of n8n? Either way, in this blog I share how you can set up n8n on your own machine using Docker and Docker Compose. In this blog I will use Portainer as my GUI to setup and manage the Docker Compose file.
What is n8n?
To start, lets briefly touch on n8n. n8n is an open-source no / low-code automation tool. The tool can be compared to SaaS solutions like Make.com (previously Integromat), Zapier and Pabbly Connect. The biggest differentiator is that n8n is open-source and it’s possible to self-host.
What is Docker Compose?
Docker Compose is an open-source tool that allows you to define and manage multi-container Docker applications using a simple YAML file. It enables you to configure all the services your Docker containers and it’s settings in one single place.
Comparable to how n8n orchestrates automation workflows, Docker Compose orchestrates containers to work together seamlessly. The biggest advantage is that it simplifies the setup and deployment process, ensuring consistency across different environments.
How to use Docker Compose to set up n8n?
In case you’ve succesfully set up Docker, Docker Compose, and Portainer on your machine, you’re ready to deploy n8n. Below, I’ll guide you through the process of setting up n8n by focusing solely on the Docker Compose file and its deployment using Portainer.
1. Docker Compose Configuration
For this setup, we’ll use a simplified Docker Compose file tailored for n8n. This configuration defines the necessary service and ensures that your data is persisted across container restarts.
Here’s the Docker Compose configuration we’ll use:
services:
n8n:
image: n8nio/n8n:latest
container_name: n8n
environment:
- GENERIC_TIMEZONE=Europe/Amsterdam
- NODE_ENV=production
- N8N_SECURE_COOKIE=false
ports:
- "5678:5678"
volumes:
- n8n_data:/home/node/.n8n
restart: unless-stopped
volumes:
n8n_data:
name: n8n_data
2. Understanding the Docker Compose Configuration
Let’s break down the key components of this configuration:
- version: Specifies the Docker Compose version. Version 3.9 is widely supported and suitable for most applications.
- services: Defines the services to be run. In this case, we have a single service named
n8n
.- image: Specifies the Docker image to use. We’re using the latest version of
n8nio/n8n
, ensuring you have the most recent features and security updates. - container_name: Names the container
n8n
for easy identification within Portainer. - environment: Sets environment variables essential for n8n’s operation:
GENERIC_TIMEZONE
: Sets the timezone for n8n, ensuring your workflows operate in the correct time context.NODE_ENV
: Defines the environment mode. Setting it toproduction
optimizes n8n for stable performance.N8N_SECURE_COOKIE
: Sets the requirement for a secure cookie. If you access your Docker instance via IP, this should be temporarily set tofalse
. It’s recommended to setup a secure connection directly.
- image: Specifies the Docker image to use. We’re using the latest version of
- volumes: Defines the
n8n_data
volume used to persist data. Docker manages this volume, ensuring data persistence without manual intervention.
3. Deploying the Docker Compose File with Portainer
Deploying n8n using Portainer is straightforward thanks to its intuitive graphical interface. Here’s how to proceed:
a. Access Portainer
- Open Portainer:
- Navigate to your Portainer instance in your web browser, typically at
http://localhost:9000
or your configured Portainer URL.
- Navigate to your Portainer instance in your web browser, typically at
- Log In:
- Enter your Portainer credentials to access the dashboard.
b. Create a New Stack
- Navigate to Stacks:
- In the left-hand menu, click on Stacks.
- Add a New Stack:
- Click the + Add stack button.
- Name Your Stack:
- Provide a name for your stack, such as
n8n-stack
.
- Provide a name for your stack, such as
- Deploy the Docker Compose File:
- In the Web editor section, paste the Docker Compose configuration provided above.
- Deploy the Stack:
- Click Deploy the stack. Portainer will handle pulling the necessary Docker image and setting up the container based on your configuration.
c. Verify the Deployment
- Check Stack Status:
- After deployment, the stack should appear in the Stacks list with a status indicating that it’s running.
- Inspect the Container:
- Click on the stack name (
n8n-stack
) to view details. - Ensure the
n8n
container is up and running without errors.
- Click on the stack name (
4. Accessing n8n
Once the stack is deployed and the container is running:
- Open n8n in Your Browser:
- Navigate to
https://localhost:5678
if you’re accessing it locally or access it via the IP of your Docker instancehttps://192.168.X.X:5678
- Navigate to
- Initial Setup:
- Upon first access, you may be prompted to create an admin account or configure basic settings. Follow the on-screen instructions to complete the setup.
5. Managing Your n8n Instance
With n8n deployed via Docker Compose and managed through Portainer, maintaining your automation platform is seamless:
- Updating n8n:
- To update n8n to a newer version, you can use a container like Watchtower to have n8n be updated to the latest version, automatically. Another option is to redeploy the stack through Portainer. Portainer will handle pulling the updated image and restarting the container.
- Backing Up Data:
- Since your workflows and configurations are stored in the
n8n_data
volume, ensure you back up this volume regularly. You can do this through Portainer by exporting the volume or using Docker commands to back up the volume data.
- Since your workflows and configurations are stored in the
- Scaling Services:
- If you need to scale your n8n instance or add additional services, update your Docker Compose file accordingly and redeploy the stack. Portainer will apply the changes, allowing for easy scalability.