Mongodb with Docker

https://university.mongodb.com/mercury/M103/2019_December_10/chapter/Chapter_1_The_Mongod/lesson/5a2f8ef0cb6b357b57e6bf2f/problem

I am trying to complete this lab. But unable to do so.

My Steps:

Launched Mongo Container

create config file with below content

net:
bindIp: 127.0.0.1,192.168.103.100
port: 27000
storage:
dbPath: /var/mongodb/db/
security:
authorization: enabled

create m103-admin user with below script
mongo admin --host localhost:27000 --eval ’
db.createUser({
user: “m103-admin”,
pwd: “m103-pass”,
roles: [
{role: “root”, db: “admin”}
]
})

Getting this error everytime

Mongod was not started by the correct user - remember NOT to run mongod as root.

I created m103-admin user on my docker container and able to connect with it using command mongo --port 27000 --username m103-admin, Mongod is not running as root user as I created the user m103-admin on the container and using it as you can see from below logs that there are no warning of admin user.

2019-12-16T20:55:25.819+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none’
2019-12-16T20:55:25.821+0000 I CONTROL [initandlisten] MongoDB starting : pid=1016 port=27000 dbpath=/var/mongodb/db/ 64-bit host=983194dac66d
2019-12-16T20:55:25.821+0000 I CONTROL [initandlisten] db version v4.2.1
2019-12-16T20:55:25.821+0000 I CONTROL [initandlisten] git version: edf6d45851c0b9ee15548f0f847df141764a317e
2019-12-16T20:55:25.821+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
2019-12-16T20:55:25.821+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-12-16T20:55:25.821+0000 I CONTROL [initandlisten] modules: none
2019-12-16T20:55:25.821+0000 I CONTROL [initandlisten] build environment:
2019-12-16T20:55:25.821+0000 I CONTROL [initandlisten] distmod: ubuntu1804
2019-12-16T20:55:25.821+0000 I CONTROL [initandlisten] distarch: x86_64
2019-12-16T20:55:25.821+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-12-16T20:55:25.821+0000 I CONTROL [initandlisten] options: { config: “/conf/mongod.conf”, net: { bindIp: “127.0.0.1,192.168.103.100”, port: 27000 }, security: { authorization: “enabled” }, storage: { dbPath: “/var/mongodb/db/” } }
2019-12-16T20:55:25.821+0000 I STORAGE [initandlisten] Detected data files in /var/mongodb/db/ created by the ‘wiredTiger’ storage engine, so setting the active storage engine to ‘wiredTiger’.
2019-12-16T20:55:25.822+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=478M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
2019-12-16T20:55:26.250+0000 I STORAGE [initandlisten] WiredTiger message [1576529726:250408][1016:0x7f43597abb00], txn-recover: Recovering log 5 through 6
2019-12-16T20:55:26.280+0000 I STORAGE [initandlisten] WiredTiger message [1576529726:280055][1016:0x7f43597abb00], txn-recover: Recovering log 6 through 6
2019-12-16T20:55:26.321+0000 I STORAGE [initandlisten] WiredTiger message [1576529726:321091][1016:0x7f43597abb00], txn-recover: Main recovery loop: starting at 5/4992 to 6/256
2019-12-16T20:55:26.386+0000 I STORAGE [initandlisten] WiredTiger message [1576529726:386573][1016:0x7f43597abb00], txn-recover: Recovering log 5 through 6
2019-12-16T20:55:26.436+0000 I STORAGE [initandlisten] WiredTiger message [1576529726:436533][1016:0x7f43597abb00], txn-recover: Recovering log 6 through 6
2019-12-16T20:55:26.465+0000 I STORAGE [initandlisten] WiredTiger message [1576529726:465534][1016:0x7f43597abb00], txn-recover: Set global recovery timestamp: (0,0)
2019-12-16T20:55:26.516+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2019-12-16T20:55:26.519+0000 I STORAGE [initandlisten] Timestamp monitor starting
2019-12-16T20:55:26.526+0000 I SHARDING [initandlisten] Marking collection local.system.replset as collection version:
2019-12-16T20:55:26.527+0000 I STORAGE [initandlisten] Flow Control is enabled on this deployment.
2019-12-16T20:55:26.527+0000 I SHARDING [initandlisten] Marking collection admin.system.roles as collection version:
2019-12-16T20:55:26.527+0000 I SHARDING [initandlisten] Marking collection admin.system.version as collection version:
2019-12-16T20:55:26.529+0000 I SHARDING [initandlisten] Marking collection local.startup_log as collection version:
2019-12-16T20:55:26.529+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory ‘/var/mongodb/db/diagnostic.data’
2019-12-16T20:55:26.542+0000 I SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version:
2019-12-16T20:55:26.542+0000 I SHARDING [LogicalSessionCacheReap] Marking collection config.transactions as collection version:
2019-12-16T20:55:26.542+0000 I NETWORK [initandlisten] Listening on /tmp/mongodb-27000.sock
2019-12-16T20:55:26.542+0000 I NETWORK [initandlisten] Listening on 127.0.0.1
2019-12-16T20:55:26.543+0000 I NETWORK [initandlisten] Listening on 192.168.103.100
2019-12-16T20:55:26.543+0000 I NETWORK [initandlisten] waiting for connections on port 27000
2019-12-16T20:55:27.000+0000 I SHARDING [ftdc] Marking collection local.oplog.rs as collection version:
2019-12-16T20:55:38.818+0000 I NETWORK [listener] connection accepted from 127.0.0.1:34354 #1 (1 connection now open)
2019-12-16T20:55:38.818+0000 I SHARDING [conn1] Marking collection admin.system.users as collection version:
2019-12-16T20:55:38.819+0000 I NETWORK [conn1] received client metadata from 127.0.0.1:34354 conn1: { driver: { version: “local build”, name: “mongo-go-driver” }, os: { type: “linux”, architecture: “amd64” }, platform: “go1.9.2” }
2019-12-16T20:55:38.827+0000 I ACCESS [conn1] Successfully authenticated as principal m103-admin on admin from client 127.0.0.1:34354
2019-12-16T20:55:38.827+0000 I NETWORK [listener] connection accepted from 127.0.0.1:34356 #2 (2 connections now open)
2019-12-16T20:55:38.828+0000 I NETWORK [conn2] received client metadata from 127.0.0.1:34356 conn2: { driver: { name: “mongo-go-driver”, version: “local build” }, os: { architecture: “amd64”, type: “linux” }, platform: “go1.9.2” }
2019-12-16T20:55:38.835+0000 I ACCESS [conn2] Successfully authenticated as principal m103-admin on admin from client 127.0.0.1:34356
2019-12-16T20:55:38.841+0000 I ACCESS [conn2] Successfully authenticated as principal m103-admin on admin from client 127.0.0.1:34356
2019-12-16T20:55:38.848+0000 I ACCESS [conn2] Successfully authenticated as principal m103-admin on admin from client 127.0.0.1:34356
2019-12-16T20:55:38.855+0000 I NETWORK [conn1] end connection 127.0.0.1:34354 (1 connection now open)
2019-12-16T20:55:38.855+0000 I NETWORK [conn2] end connection 127.0.0.1:34356 (0 connections now open)
2019-12-16T20:56:14.298+0000 I NETWORK [listener] connection accepted from 127.0.0.1:34556 #3 (1 connection now open)
2019-12-16T20:56:14.298+0000 I NETWORK [conn3] received client metadata from 127.0.0.1:34556 conn3: { application: { name: “MongoDB Shell” }, driver: { name: “MongoDB Internal Client”, version: “4.2.1” }, os: { type: “Linux”, name: “Ubuntu”, architecture: “x86_64”, version: “18.04” } }
2019-12-16T20:56:14.323+0000 I ACCESS [conn3] Successfully authenticated as principal m103-admin on admin from client 127.0.0.1:34556
2019-12-16T20:57:19.675+0000 I NETWORK [conn3] end connection 127.0.0.1:34556 (0 connections now open)
2019-12-16T20:58:11.393+0000 I NETWORK [listener] connection accepted from 127.0.0.1:35224 #4 (1 connection now open)
2019-12-16T20:58:11.393+0000 I NETWORK [conn4] received client metadata from 127.0.0.1:35224 conn4: { driver: { name: “mongo-go-driver”, version: “local build” }, os: { type: “linux”, architecture: “amd64” }, platform: “go1.9.2” }
2019-12-16T20:58:11.401+0000 I ACCESS [conn4] Successfully authenticated as principal m103-admin on admin from client 127.0.0.1:35224
2019-12-16T20:58:11.402+0000 I NETWORK [listener] connection accepted from 127.0.0.1:35226 #5 (2 connections now open)
2019-12-16T20:58:11.402+0000 I NETWORK [conn5] received client metadata from 127.0.0.1:35226 conn5: { driver: { name: “mongo-go-driver”, version: “local build” }, os: { architecture: “amd64”, type: “linux” }, platform: “go1.9.2” }
2019-12-16T20:58:11.409+0000 I ACCESS [conn5] Successfully authenticated as principal m103-admin on admin from client 127.0.0.1:35226
2019-12-16T20:58:11.416+0000 I ACCESS [conn5] Successfully authenticated as principal m103-admin on admin from client 127.0.0.1:35226
2019-12-16T20:58:11.422+0000 I ACCESS [conn5] Successfully authenticated as principal m103-admin on admin from client 127.0.0.1:35226
2019-12-16T20:58:11.427+0000 I NETWORK [conn4] end connection 127.0.0.1:35224 (1 connection now open)
2019-12-16T20:58:11.427+0000 I NETWORK [conn5] end connection 127.0.0.1:35226 (0 connections now open)

It could be issue with ownership of files
Who owns the dir’s
I am not sure how docker works

Hi @Muhammad_Abdul_Rehman_22238,

I don’t have the debugging information available with me at the moment. Let me sync with someone in the curriculum team and I will get back to you shortly.

Thanks,
Shubham Ranjan
Curriculum Support Engineer

I changed the owner as well. Please do let me know, from which user scripts want to initiate mongod. As I tried both user i.e. root and m103-admin.

Thank you. I will wait for your response, as I want to complete the course as soon as possible.

I believe that Docker is running the mongod with elevated privileges, i.e. sudo, and I think this is the default user Docker runs as, hence the validation error message you’re seeing.

You need to look for a way of running Docker as a non-root user and that should resolve this problem.

Thank you. I figured it out. It requires user name vagrant only. I was using non root user as m103-admin. Today I created the user vagrant and it works fine.

Hi @Muhammad_Abdul_Rehman_22238,

I’m glad your issue got resolved. If you face any difficulty then please feel free to get back to us.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer