Articles

How to Run n8n with Docker (Beginner's Guide)

Imagine automating your workflows, connecting apps, APIs, and services without writing endless lines of code. That’s exactly what n8n (short for “nodemation”) helps us do. It’s an open-source workflow automation tool that we can self-host. Not only that, but one of the easiest and most reliable ways to host n8n is with Docker.

In this article, we will provide a clear, step-by-step guide on how to host n8n using Docker. We will include best practices from the open-source community to ensure a smooth process. If you’re new to Docker, check out What is Docker?. Then, for a quick overview, check out Docker Container.

Setting up n8n and Docker

Step 1: install Docker

First, you’ll need Docker installed on your machine. Head over to the Docker website and download the installer for your operating system.

For a more detailed walkthrough, see our guide on Setting up Docker.

Once installed, confirm Docker is running correctly with:

docker --version

Docker version check

This should print your Docker version.

Step 2: create a Docker compose file

Instead of manually typing long docker run commands, we’ll use Docker Compose to define how n8n should run. Docker Compose lets you manage multi-container setups easily. Learn more with our guide on Mastering Docker Compose.

In your project folder, create a file called docker-compose.yml and paste the following:

version: '3.1'
services:
n8n:
image: n8nio/n8n
ports:
- "5678:5678"
environment:
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=secretpassword
volumes:
- ./n8n_data:/home/node/.n8n

What this file does:

  • image: Uses the official n8n Docker image.
  • ports: Exposes n8n on port 5678.
  • environment: Sets up basic authentication so only you can log in.
  • volumes: Persists your n8n workflows locally so they don’t get lost when containers restart.

Step 3: start n8n with Docker

From your terminal, run:

docker compose up -d

This downloads the n8n image (if you don’t already have it) and runs the service in the background.

To check if everything is working, run:

docker ps

You should see an entry for n8nio/n8n running.

Or, you can install n8n using the Docker Desktop application:

Searching for n8n image in Docker Desktop

Downloading n8n from Docker Desktop

Step 4: access the n8n dashboard

Once the compose is finished running, open your browser and go to:

http://localhost:5678

You’ll be prompted to log in using the credentials you set in the docker-compose.yml file (admin / secretpassword).

Login into n8n

Once logged in, you’ll see n8n’s visual editor, where you can create workflows by dragging and dropping nodes.

n8n interface hosted by Docker

Step 5: stopping and managing n8n

To stop n8n:

docker compose down

To update n8n, pull the latest Docker image:

docker compose pull
docker compose up -d

Your workflows are safe because they’re stored in the n8n_data volume.

Why use Docker for n8n?

Docker makes it simple to package applications like n8n into containers: lightweight, portable environments that include everything the app needs to run. Instead of worrying about dependencies and environment setup, Docker ensures n8n runs similarly on any system.

Best practices for hosting n8n on Docker

  • Always enable authentication (N8N_BASIC_AUTH_ACTIVE=true) in your compose file when hosting n8n.
  • Use a reverse proxy like Nginx or Traefik if deploying n8n to a server.
  • Persist data with Docker volumes so you don’t lose workflows.
  • Keep your n8n Docker image updated regularly.

Conclusion

Congratulations on completing this hosting n8n using Docker tutorial! By hosting n8n on Docker, you get a powerful, self-hosted automation tool that’s simple to run and maintain. With just a few lines in a Docker Compose file, you’re up and running in minutes.

If you’re new to Docker or want to dive deeper, don’t miss these helpful guides:

Frequently asked questions

1. Is n8n free to use?

Yes, n8n is open source and free to use. There’s also an enterprise plan with additional features if needed.

2. What port does n8n run on by default?

By default, n8n runs on port 5678, which you can expose or change in your Docker Compose file.

3. Can I use n8n in production with Docker?

Absolutely. Using Docker makes n8n more reliable in production because it isolates dependencies and allows you to persist workflows with volumes.

4. How do I update my n8n installation in Docker?

You can run:

docker compose pull
docker compose up -d

This fetches the latest image and restarts n8n while keeping your workflows intact. Or simply update it from Docker Desktop when needed.

5. Can I secure my n8n instance?

Yes. You should enable authentication, run n8n behind a reverse proxy (like Nginx), and use HTTPS certificates for secure connections.

Codecademy Team

'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'

Meet the full team