Run n8n Locally for Free with Docker (Part 5 of 10): A Cleaner Setup with Docker Compose
By Abhishek Patoliya · 2026-08-12
This is Part 5 of the series on running n8n locally with Docker for free. The docker run command from Part 4 works, but it's already long, and every new setting from here on (Part 6's environment variables, for instance) would make it longer still. Docker Compose fixes this by moving all of it into one readable file.
← Back to the full series index
Creating docker-compose.yml
In a new folder for your n8n setup, create a file named docker-compose.yml:
services:
n8n:
image: n8nio/n8n
container_name: n8n
restart: unless-stopped
ports:
- "5678:5678"
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:
This is the exact same setup as Part 4's docker run command — same image, same port mapping, same named volume — just expressed as a file instead of a command line.
What's New Here: restart: unless-stopped
This one line is genuinely new value Compose adds easily: it tells Docker to automatically restart the n8n container if it crashes, or after your machine reboots — something the plain docker run command from earlier parts didn't handle. Your local n8n instance now comes back up on its own after a restart, rather than needing you to remember to start it manually.
Starting and Stopping
From the folder containing docker-compose.yml:
docker compose up -d
This reads the file and starts everything it defines, in the background. To stop it:
docker compose down
This stops and removes the container, but — because the volume is declared separately in the file — your data is untouched. Bring it back up with docker compose up -d again, and everything is exactly where you left it.
Checking Status and Logs
docker compose ps
docker compose logs -f
These work the same way as the equivalent plain docker commands from Part 3, just scoped to whatever's defined in this Compose file — useful once you have more than one service running together.
Why This Matters Going Forward
Every setting the rest of this series adds — environment variables in Part 6, and any future addition like an external database — is just another line or block in this same file. You edit docker-compose.yml, run docker compose up -d again, and Docker applies just the changes, recreating only what actually needs it. This file is also the thing worth keeping in version control (a private Git repo, even just locally) so your entire setup is reproducible from one file if you ever need to rebuild it on a new machine.
Next Up
Continue to Part 6: Environment Variables That Actually Matter, which adds the handful of settings worth configuring deliberately rather than leaving on their defaults.
Written by Abhishek Patoliya, Senior n8n Developer & Automation Architect, Surat, India. Verified n8n Creator.