Home > Software > How to Set Up n8n with Docker Compose: n8n Docker Compose

How to Set Up n8n with Docker Compose: n8n Docker Compose

Anastasios Antoniadis

Learn to effortlessly set up n8n, an automation platform, using Docker Compose with our concise guide.

Docker (1)

n8n (pronounced “n-eight-n”) offers a powerful, node-based approach to automating tasks across various services and APIs. Whether you’re integrating CRM systems, sending automated emails, or syncing files between services, n8n can handle it all. Deploying n8n in a Dockerized environment further simplifies the setup and scalability of your automation workflows. This article provides an insightful guide on deploying n8n using Docker Compose, including a practical example to kickstart your automation journey.

Understanding n8n and Docker Compose

n8n is an extendable workflow automation tool that enables you to connect anything to everything via its web-based visual workflow editor. It supports various modules for different services and offers flexibility for custom function nodes.

Docker Compose is a tool for defining and running multi-container Docker applications. With a simple YAML file, you can configure all your application’s services and manage them with single commands.

Why Use Docker Compose for n8n?

Deploying n8n with Docker Compose offers numerous benefits:

  • Simplicity: Launching n8n with just a few commands streamlines the setup process.
  • Portability: Docker Compose files can be easily shared or version-controlled, ensuring consistent environments across teams and deployments.
  • Scalability: Docker Compose facilitates scaling your n8n instances and integrating additional services like databases or custom apps.

Example n8n Docker Compose File

Below is an example docker-compose.yml file for deploying n8n, which includes n8n and an optional PostgreSQL database for persistent storage.

version: '3.1'

services:
  n8n:
    image: n8nio/n8n
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=password
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=n8n
      - DB_POSTGRESDB_PASSWORD=password
    depends_on:
      - postgres

  postgres:
    image: postgres:13
    restart: unless-stopped
    environment:
      - POSTGRES_USER=n8n
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=n8n
    volumes:
      - postgres-data:/var/lib/postgresql/data

volumes:
  postgres-data:

Step-by-Step Setup Guide

  1. Install Docker and Docker Compose: Ensure both Docker and Docker Compose are installed on your machine.
  2. Prepare the Docker Compose File: Create a docker-compose.yml file in your project directory and paste the example configuration.
  3. Customize Your Setup: Modify environment variables as needed, such as changing the default N8N_BASIC_AUTH_USER and N8N_BASIC_AUTH_PASSWORD to secure your n8n instance.
  4. Launch n8n: Navigate to your project directory in a terminal and run docker-compose up -d. Docker Compose will start n8n and PostgreSQL, linking them together based on the configuration.
  5. Access n8n: Once the containers are running, access n8n by navigating to http://localhost:5678 in your web browser. Log in using the credentials you set up in the environment variables.

Best Practices and Tips

  • Data Persistence: The example includes a volume for PostgreSQL to ensure data persistence across container restarts.
  • Security: Always change the default passwords and consider using environment variables or .env files to manage sensitive information securely.
  • Scalability: As your workflow complexity grows, consider adding additional n8n workers or database replicas to handle increased load.

Conclusion

Deploying n8n with Docker Compose offers a flexible, scalable solution for workflow automation. By following the example provided and customizing it to fit your needs, you can set up a robust automation system that integrates seamlessly with your existing tools and services. Whether you’re a small business looking to automate repetitive tasks or a developer orchestrating complex workflows, n8n and Docker Compose provide a powerful combination to streamline your processes.

Anastasios Antoniadis
Follow me
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x