Setting Up n8n in a Docker Container with Docker Compose from Local Files

Hi there, I’m a developer interested in using the n8n tool. My objective is to set up the n8n environment within a Docker container using Docker Compose. I’d like the image to be built from local files. Additionally, when I make changes to the backend or frontend, the relevant service should automatically apply these changes without requiring me to manually down and up the Docker container. Perhaps mounting the volume of those folders into the container would be a solution? Is this feasible? Thanks a lot!

1 Like

Hey @wulukewu welcome to the community.
So you’re trying to set up n8n with Docker Compose and you want it to automatically update when you make changes to the backend or frontend code.

Mounting volumes is definitely the way to go here. By mapping your local code folders to the container, you can enable hot reloading and avoid having to restart the container every time you make changes.

taking a look at your docker-compose.yml file. You need to add the volume mounts for the backend and frontend folders. Something like this:
volumes:

  • ./backend:/app/backend
  • ./frontend:/app/frontend

This will map your local backend and frontend folders to the corresponding folders in the container.

You also need to make sure that the container is set up to watch for file changes and reload automatically. Depending on how you’ve configured n8n, you might need to add some environment variables or use a tool like nodemon to enable hot reloading.

Have you got a Dockerfile set up for your n8n image?

I tried to alter the files so I can build with Typescript support and watch mdoe inside a Docker container, but was unsuccessful. Ultimately I gave up and just decided I will run it locally outside Docker as that works OK.

Interested if anyone manages to run it inside Docker with nodemon or other methods.

Well, I’ve created a docker-compose.yml file in the root directory, and I can access the page in my browser using docker-compose up. However, when I attempted to mount the folders in the volumes, I’m at a loss as to how to set up the command to automatically apply the changes to the container. I tried adding something like command: pnpm dev, but it only resulted in errors. I’m curious if anyone has encountered this issue before and could provide guidance.

version: '3.8'

services:
  n8n:
    container_name: n8n_dev
    image: docker.n8n.io/n8nio/n8n
    restart: unless-stopped
    ports:
      - "5678:5678"
    volumes:
      - n8n_data_dev:/home/node/.n8n
    environment:
      - N8N_HOST=${N8N_HOST:-localhost}
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - WEBHOOK_URL=http://${N8N_HOST:-localhost}:5678/
volumes:
  n8n_data_dev:

You won’t be able to achieve this with the official image, because it runs compiled files and doesn’t include pnpm and other dev dependencies, to my knowledge.

I was thinking on something like this, but haven’t tested it yet:

version: '3.8'

services:
  n8n:
    container_name: n8n_dev
    build:
      context: ./n8n  # path to cloned repo
      dockerfile: Dockerfile
    ports:
      - "5678:5678"
    volumes:
      - ./n8n:/home/node/n8n  # mount local repo
      - n8n_data_dev:/home/node/.n8n
    environment:
      - N8N_HOST=localhost
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - WEBHOOK_URL=http://localhost:5678/
    command: pnpm dev  # only works if image has pnpm and dependencies
volumes:
  n8n_data_dev:

1 Like

Okay, so “pnpm install” and “npm run dev” work on my local machine, but when I try the same thing using Docker, it stops when installing packages. The error I get is something like this:

> [7/8] RUN pnpm install --frozen-lockfile: 2.241  ERR_PNPM_CATALOG_IN_OVERRIDES Could not resolve a catalog in the overrides: No catalog entry '@sentry/node' was found for catalog 'default'. 

And even if I change the version of package.json, it still doesn’t work when I try to run the dev command. So, I guess I have to run it outside of Docker.

Yes, I’ve had the same experience and decided to just run it locally. But did you had the chance to try with my docker file? THe key thing is properly mounting the local cloned repo to the container volume, so it works as if you cloned the repo in the container. I might try as well when I have some free time too.

Okay, I attempted to modify your Docker-compose file by changing the mounted volume to .:/home/node and the Docker file path to dockerfile: .devcontainer/Dockerfile in the root directory of this repository. However, it appears that this change is not working.

Attaching to n8n_dev
n8n_dev  |  ERROR  Command was killed with SIGKILL (Forced termination): pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_315/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_304/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_293/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_282/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_271/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_260/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_249/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_238/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_227/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_216/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_205/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_194/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_183/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_172/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_161/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_150/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_139/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_128/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_117/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_106/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_95/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_84/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_73/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_62/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_51/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_40/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_29/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_18/bin
n8n_dev  | For help, run: pnpm help add
n8n_dev  |  ERROR  Command failed with exit code 1: pnpm add [email protected] --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=/home/node/.local/share/pnpm/.tools/pnpm/10.12.1_tmp_1/bin
n8n_dev  | For help, run: pnpm help run
n8n_dev exited with code 1