Docker Community Forums

Share and learn in the Docker community.

Mongod does not run in the background as non-root

Hey everyone,

I’m building my first image. Everything worked with my Dockerfile.
I used the official mongoDB image as a base and installed a node App inside that image.

I try to run mongod in the background with mongod --fork --logpath ~/log and after that i run the node App (server.js).

But mongod just gives this error:

about to fork child process, waiting until server is ready for connections.
forked process: 10
ERROR: child process failed, exited with 1
To see additional information in this output, start without the "--fork" option.

When I run the same command as root, everything works. But then I also run my node server as root and that’s not what I want.

I use a script as my CMD [ "/start.sh" ] in my Dockerfile

The script.sh looks like this:

#!/bin/bash

mkdir log
mongod --fork --logpath ~/log
node server.js

What do i have to do to run mongod in the background as non-root user?
Or is there a way to run mongod as root and node server.js as my user?

Thanks in advance!