Article DetailsDetailsHelp Details When running Neo4j Docker, it will run by default as neo4j user inside the container. To run docker as a different user one can specify the --user argument. Documentation has a section for running as non-root user: https://neo4j.com/docs/operations-manual/current/docker/introduction/#docker-user When using the --user flag it needs to have a valid, non-root user value provided. Our Docker container assumes/requires that the user is a) not root b) has write access to data and logs directories and has read access to conf directory. It is important to note that if you are passing 0:0 or 0 or root etc. as --user, it will still not use root to run neo4j but the container will use its own internal neo4j user and neo4j user group (these happen to currently have uid 101 and gid 101 but that should NOT be relied upon). The Docker entrypoint is specifically written to avoid running the neo4j docker image as root. The best approach here is to create a user and group and pass that on to the Docker input via --user. Create a user neo4j without a home directory$ sudo useradd -M neo4jPrevent neo4j from logging in$ sudo usermod -L neo4jCreate data dir.$ sudo mkdir -p /neo4j/data $ sudo chown -R neo4j /neo4j/data $ sudo chgrp -R neo4j /neo4j/dataNote: we only give group read permissions here$ sudo chmod -R u+rwX,g+rX,o-wrx /neo4j/dataWe do not recommend any application other than neo4j writing to the data dir. This can corrupt the data store.$ sudo mkdir -p /neo4j/conf $ sudo chown -R neo4j /neo4j/conf $ sudo chgrp -R neo4j /neo4j/confAssign Group write permissions for config$ sudo chmod -R u+rX,g+rwX,o-wrx /neo4j/confNote: External changes to the conf dir you require restart the docker image to pickup new configuration (conf is copied from the mounted volume on startup).Create plugins dir$ sudo mkdir -p /neo4j/plugins $ sudo chown -R neo4j /neo4j/plugins $ sudo chgrp -R neo4j /neo4j/pluginsAssign Group write permissions for plugins$ sudo chmod -R u+rwX,g+rwX,o-wrx /neo4j/pluginsNote: External changes to the plugins dir you require restart the docker image to pickup new configuration (plugins loaded on startup).Configure logs directory - Let’s assume that the logs dir is being used by multiple applications n.b. if something interferes with neo4j writing logs it can crash the neo4j process. Create a logs group for all things log related$ sudo groupadd logsAdd neo4j to logs group$ sudo usermod -a -G logs neo4j $ sudo mkdir -p /logs/neo4j $ sudo chown -R root /logs/neo4j $ sudo chgrp -R logs /logs/neo4j $ sudo chmod -R u+rwX,g+rwX,o-wrx /logs/neo4jIf docker does not run as root$ docker_user=root $ sudo usermod -a -G logs "${docker_user}" $ sudo usermod -a -G neo4j "${docker_user}"Add ourselves to the neo4j group so /neo4j/* dirs created above can be read and edited.$ current_user=$(id -un) $ sudo usermod -a -G neo4j "${current_user}"Start a new shell to pick up this group assignment.Note: Docker doesn’t pull in secondary groups automatically so one has to do this explicitly:$ groups=( $( id --real --groups neo4j ) ) $ docker run \ --publish=7474:7474 --publish=7687:7687 \ --volume=/neo4j/data:/data \ --volume=/neo4j/plugins:/plugins \ --volume=/neo4j/conf:/conf \ --volume=/logs/neo4j:/logs \ --user="$(id -u neo4j):$(id -g neo4j)" \ --group-add=$groups \ neo4j:3.4 InformationTitleRunning Docker as Non-Root UserArticle Created Date3/15/2024, 10:55 PMURL Name360012923574-Running-Docker-as-Non-Root-UserLast Modified Date9/28/2025, 11:12 AM