How to resolve n8n container permissions issue in GitHub Actions?

I’m having trouble with our docker compose setup in GitHub Actions. It works fine on our local machines (macOS), but fails on the GitHub runner with a permission error:

Error: EACCES: permission denied, open '/home/node/.n8n/config'

This happens with our n8n container, which should start an HTTP API. Here’s a snippet from our docker-compose file:

workflow_engine:
  image: workflow.io/workflowio/workflow_engine
  ports:
    - "1234:1234"
  environment:
    - ENGINE_HOST=workflow_engine:1234
    - ENGINE_PORT=1234
    - ENGINE_PROTOCOL=http
    - NODE_ENV=production
    - DB_TYPE=mydb
    - DB_TABLE_PREFIX=wf_
    - DB_MYDB_DATABASE=workflow
  volumes:
    - ./CONTAINERS/workflow_engine/data:/home/user/.workflow_engine
    - ./CONTAINERS/workflow_engine/files:/files

Our GitHub Actions workflow looks like this:

sudo useradd -m user
mkdir -p CONTAINERS/workflow_engine
sudo chmod -R 777 CONTAINERS/workflow_engine
sudo chown -R user:user CONTAINERS/workflow_engine
docker-compose up -d

I’ve tried different permissions and user setups, but nothing seems to work. Any ideas on how to fix this?

have u tried runnin the container as root? add user: root to ur compose file for the n8n service. also check if the volume paths exist on the runner. sometimes these issues happen cuz of missin directories. lemme kno if that helps!

The permission issue you’re encountering is likely due to the mismatch between the container’s user and the host system’s file ownership. Instead of modifying the container to run as root, which can pose security risks, consider adjusting your approach:

Update your docker-compose file to use a named volume for n8n data:

volumes:
  - n8n_data:/home/node/.n8n

Modify your GitHub Actions workflow to create and set permissions on this volume:

docker volume create n8n_data
docker run --rm -v n8n_data:/data alpine chmod 777 /data

This method ensures proper permissions without compromising security. It also simplifies your setup by avoiding host-bound volumes, which can be tricky in CI environments.

I’ve dealt with similar permission issues when running containers in CI environments. One approach that’s worked well for me is using the --user flag in your docker-compose file to match the UID and GID of the host system. You can do this dynamically in your GitHub Actions workflow:

- name: Get host UID/GID
  run: |
    echo \"UID=$(id -u)\" >> $GITHUB_ENV
    echo \"GID=$(id -g)\" >> $GITHUB_ENV

- name: Start containers
  run: docker-compose up -d --user \"$UID:$GID\"

This ensures the container processes run with the same permissions as the GitHub Actions runner, which should resolve the EACCES error. Also, double-check that your volume paths are correct and accessible on the runner. If issues persist, you might need to initialize the volume directories with the correct permissions before starting the containers.