Mongo: Mongo user in dockerfile added as default system user uid.

Created on 19 May 2017  路  6Comments  路  Source: docker-library/mongo

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

image

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

image

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

image

I'm wondering what people have done to get around this. Basically the container has all the rights of the mapped user now.

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).

All 6 comments

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

  • In specific case of Kali Linux (this is what I am using): uid, gid 999 maps to user: systemd-coredump
  • /etc/passwd entry: systemd-coredump:x:999:999:systemd Core Dumper:/:/sbin/nologin
  • It's may not be the real problem because only the specific user only can edit/modify the data, but not sure about the side effects of using the systemd-coredump user outside the container but which was mapped to mongodb user inside the container

Solution
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

Details and scripts here

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vito-c picture vito-c  路  4Comments

tdaleibm picture tdaleibm  路  5Comments

sri85 picture sri85  路  7Comments

imaia picture imaia  路  6Comments

bimalm picture bimalm  路  5Comments