The dockerfile adds mongodb user as system user which in turn creates a user with a uid of 999.

On our host we happen to have another default system user with a uid of 999.

When we run the docker container it gets mapped to this user.

I'm wondering what people have done to get around this. Basically the container has all the rights of the mapped user now.
While the mongo user is user 999, it can only access things given to it inside the container.
https://github.com/docker-library/mongo/pull/81 added the ability to run as an arbitrary user, docker run --user some-other-user-id:some-group-id (up to you to ensure chosen user/group has access to any bind mounted files).
in this case. user 999 can access the container tho right.
i guess we'll go with a random uid then. thanks.
@yosifkit getting this running as another user
17:51:29 2017-05-22T17:51:28.895+0000 I CONTROL [initandlisten] options: {}
17:51:29 2017-05-22T17:51:28.912+0000 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
i'm not using a host volume
does the startup handle chowning the data directory to the user passed it?
It cannot chown. If you start the container with --user to docker run, then it is not root and cannot chown files owned by another user. It seems that #81 did not chmod 777 the directory in the Dockerfile since that would be insecure for database files. So I think if you want to run as a specific user, you have to provide a data directory that it can write to.
We did add some notes for arbitrary users in postgres, but have not added anything for mongo, mysql, mariadb, or percona.
in that case, think id prefer to run it as the user starting the container, however in that case that user needs to exist in the container then
Old thread, but posting the solution in case someone finds it useful. Currently, it has different options to get this working, but you need to justify your case. For example, in my case, the data volume is mapped to the mongodb docker container created using official mongodb docker image, it always creates the mongodb user with uid=999 and gid=999, which translates to the following problem.
Problem
systemd-coredump:x:999:999:systemd Core Dumper:/:/sbin/nologinSolution
a) create a mongodb user and group on the host machine
b) pass the user, group, uid, gid as arguments to the official mongodb dockerfile
b) build the image by passing the values to the respective arguments
Most helpful comment
While the mongo user is user 999, it can only access things given to it inside the container.
https://github.com/docker-library/mongo/pull/81 added the ability to run as an arbitrary user,
docker run --user some-other-user-id:some-group-id(up to you to ensure chosen user/group has access to any bind mounted files).