We do this for queue mode. We actually create a named docker volume, install the community nodes there, and then mount that to all our n8n containers:
To create/update the volume and community nodes:
docker volume create n8n-custom-nodes
# Set the directory permissions to the node user
docker run --rm \
-v n8n-custom-nodes:/custom \
--entrypoint /bin/sh \
n8nio/n8n \
-c "chown -R 1000:1000 /custom"
# Install the community nodes
docker run --rm \
-v n8n-custom-nodes:/custom \
n8nio/n8n \
npm install --prefix /custom n8n-nodes-ldap n8n-nodes-mjml
Then you just need to mount that named volume to /home/node/.n8n/custom
in your containers
volumes:
- n8n-custom-nodes:/home/node/.n8n/custom