Adding workflows to Docker

Hello, whenever I try to deploy using docker and activate my workflows; I need to go to the UI enter my creds and deactivate then activate my workflows but I am doing that in my Dockerfile.
Also I get the message “Please restart n8n for changes to take effect if n8n is currently running.”; how can I do that?

Here is my Dockerfile:-

Use the Node.js base image

FROM node:18

Set environment variables for authentication (replace placeholders with your actual values)

ENV N8N_BASIC_AUTH_ACTIVE=true
ENV N8N_BASIC_AUTH_USER=username
ENV N8N_BASIC_AUTH_PASSWORD=password

Create a directory for n8n

WORKDIR /usr/src/app

Install n8n globally

RUN npm install -g n8n

Copy your workflow JSON files into the container

COPY ./workflows/*.json /usr/src/app/workflows/

Expose port if n8n runs on a specific port

EXPOSE 5678

Import workflows and start n8n

CMD n8n import:workflow --separate --input=/usr/src/app/workflows/ &&
n8n update:workflow --all --active=true &&
n8n start

Information on your n8n setup

  • n8n version: Latest
  • Database (default: SQLite): Yes
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Ubuntu

Hey @Mina_Mamdouh,

Welcome to the community :raised_hands:

I am not sure I fully understand what you are trying to do, I am also not sure why you don’t use the docker image we provide then map the volume and use the command to import / activate.

Hello @Jon

Thanks for the warm welcome. I am happy to be here :slight_smile:

The current situation with this image is that my workflows are imported and activated, but I need to connect to the web UI, input my credentials, and toggle the imported workflows to be active.

I am trying to make a Dockerfile where I can do this without needing to connect to the web UI.

If there is a better way to do that, I will appreciate your help.

Thanks in advance.

Hey @Mina_Mamdouh,

Depending on the credentials you may need to connect anyway, can you share why you are doing this? I am not sure what problem it is actually solving.

Hello @Jon,

I am trying to make a POC that we can deploy on Docker, then I can try using Kubernetes, and when Kubernetes scales up, I don’t want to connect to the pod and have this manual step of setting up the credential. I want to have all the flow automated.

Hey @Mina_Mamdouh,

If you were scaling n8n they would all point to the same postgres database and you would just be adding workers. Because of the database sharing they woud all contain the workflows and credentials so this may not be needed.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.