Introduction
n8n allows you to create workflows quickly through a drag and drop interface. It contains a large list of existing integrations and allows you to create custom integrations. The n8n community has a page were they share their workflows, the majority of which is free. I recommend you visit the page to get an idea of what kind of workflows you can create. You can find the workflows here: https://n8n.io/workflows/.
In this article we will go over setting up n8n locally using docker compose. This setup will allow us to expand in the future by running additional containers side-by-side with our n8n container. For example, we can add a Wordpress container, then integrate the n8n chatbot with out Wordpress container (something I'll have an article on in the future).
All of this can be done locally using docker as containers use minimum resources.
Installing Docker for Windows, MacOS or Linux
The most convenient way is to use Docker Desktop, the interface allows you to view the containers, their resource usage, the volumes, container logs and even copy files in and out of containers.
To install Docker Desktop, visit docker.com and download docker desktop based on your operating system. Additionally you'll need to create an account which is free for personal use.
Creating compose.yml file
Docker Dekstop comes with docker compose by default, which allows us to spin up multiple containers in seconds.
Organize your docker projects by creating a directory for docker projects, then within it create an n8n directory where we will store our compose.yml file, feel free to use any text editor to create the file, then add the following contents to it:
services:
n8n:
image: docker.n8n.io/n8nio/n8n
container_name: n8n
ports:
- "5678:5678"
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:
Let's go over each section in our compose file.
Services contains our containers, in this case only a single n8n container.
In image we specify the image name which can be found on the official n8n.io website.
container_name is used to specify the name of the container, later we can use that name to run various commands on the container, such as starting, stopping and restarting the container.
ports maps the container port with the host port, in our case we are mapping the same ports. If you have multiple n8n containers running, you could map it's port to a different host port. The port to the left is for the host port and the port to the right is the containers port.
volumes allow you to store data from the container on your host machine, this keeps the data persistent (workflows, users and credentials), even after restarting or updating the container (as long as you don't delete the volume). Notice that we declare the volume at the very bottom of our yml file before mapping it to a path within our n8n container where n8n data is stored.
Starting the Container
Before starting the container, make sure that Docker Desktop is up and running by opening the application.
Using your preferred cli, make sure you are located in the same directory containing our compose.yml file, then start the container by running:
docker compose up -d
The -d flag is used to run the container in the background (detached mode).
Accessing Your n8n Application
Now if you visit the Docker Desktop application, you will find the n8n project that has an n8n container running within it. If you click on the ports section of our n8n container, it will open the n8n application in the browser. Or visit it by typing http://localhost:5678/ in your browser.
You'll be asked to create a new account. After logging in you'll receive 2 pop ups one being a questioner, the second will ask for your email address to send you a free license key, make sure you add the correct email to receive the license key.
After receiving the license key you can activate it by clicking on the triple dots next to your name at the bottom left corner, then settings, there you'll find the enter your activation key button, click on it and paste your activate key there.
Create Your First Workflow (RAG ChatBOT)
n8n comes with a cool RAG chatbot starter template, to create it click on the plus icon and select workflow, next click tab or the plus icon in the top right corner and search for rag starter template and select it. The only thing that you'll need for this workflow to work is to create an OpenAI api key, next click on the OpenAI Chat Model and click on select credentials > create new credentials, add your openAI key and save it, then add the same credentials in the Embeddings OpenAI node.
Now execute the workflow and upload a document which you'd like the chat model to use as reference. Now you can chat with the model by asking it topics related to the document.