others-how to solve mongo OCI runtime exec failed: exec failed: unable to start container process unknown problem ?

1. Purpose

In this post, I will demonstrate how to solve the following problem when trying to connect mongodb in docker using docker exec -it command:

[root@mx mongodb]# docker exec -it d51c4e0b50b2 mongo
OCI runtime exec failed: exec failed: unable to start container process: exec: "mongo": executable file not found in $PATH: unknown

The environment:

[root@mx mongodb]# docker ps
CONTAINER ID   IMAGE               COMMAND                  CREATED         STATUS                  PORTS                                                                                                                                                                                                                                                                                                                               NAMES
d51c4e0b50b2   mongo               "docker-entrypoint.s…"   4 minutes ago   Up 4 minutes  >27017/tcp, :::27017->27017/tcp

[root@mx mongodb]# docker images
REPOSITORY          TAG       IMAGE ID       CREATED        SIZE
mongo               latest    b70536aeb250   2 weeks ago    695MB

The start script of docker mongodb container:

[root@mx mongodb]# cat start_with_docker.sh
docker run -m 100M --memory-swap -1 --name mongodb -p 27017:27017 -d mongo

2. Solution

According to this: https://github.com/docker-library/mongo/issues/558

We should use mongosh instead of mongo:

What is mongosh?

The MongoDB Shell, mongosh, is a fully functional JavaScript and Node.js 16.x REPL environment for interacting with MongoDB deployments. You can use the MongoDB Shell to test queries and operations directly with your database.

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

We should use mongosh as follows:

[root@mx mongodb]# docker exec -it d51c4e0b50b2 mongosh
Current Mongosh Log ID: 636b56ebfa172ca6a7f5fbec
Connecting to:      mongodb://
Using MongoDB:      6.0.2
Using Mongosh:      1.6.0

To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

   The server generated these startup warnings when booting
   2022-11-09T07:20:03.976+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
   2022-11-09T07:20:03.976+00:00: The configured WiredTiger cache size is more than 80% of available RAM. See http://dochub.mongodb.org/core/faq-memory-diagnostics-wt
   2022-11-09T07:20:04.842+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2022-11-09T07:20:04.845+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
   2022-11-09T07:20:04.845+00:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
   2022-11-09T07:20:04.845+00:00: vm.max_map_count is too low

   Enable MongoDB's free cloud-based monitoring service, which will then receive and display
   metrics about your deployment (disk utilization, CPU, operation statistics, etc).

   The monitoring data will be available on a MongoDB website with a unique URL accessible to you
   and anyone you share the URL with. MongoDB may use this information to make product
   improvements and to suggest MongoDB products and deployment options to you.

   To enable free monitoring, run the following command: db.enableFreeMonitoring()
   To permanently disable this reminder, run the following command: db.disableFreeMonitoring()

test> show dbs

It works!

3. Summary

In this post, I demonstrated how to connect mongodb in docker using mongosh. That’s it, thanks for your reading.