OCI runtime exec failed: exec failed: unable to start container process: exec: "mongo": executable file not found in $PATH: unknown

时间:2022-10-16 13:10:41

前言:

  今天按照以往在Docker安装MongoDB的方式安装,但是到最后使用mongo命令执行mongodb命令的时候一直执行不成功,最后还是按照官网的Issues解决了。

创建并运行一个MongoDB容器:

docker run -itd --name mongo-test -p 27017:27017 mongo --auth

参数说明:

  • -itd:其中,i是交互式操作,t是一个终端,d指的是在后台运行。
  • --name mongo-test:容器名称
  • -p 27017:27017 :映射容器服务的 27017 端口到宿主机的 27017 端口。外部可以直接通过 宿主机 ip:27017 访问到 mongo 的服务。
  • --auth:需要密码才能访问容器服务。

OCI runtime exec failed: exec failed: unable to start container process: exec: "mongo": executable file not found in $PATH: unknown

OCI runtime exec failed: exec failed: unable to start container process: exec: "mongo": executable file not found in $PATH: unknown

解决无法正常执行mongo命令问题

进入容器:

docker exec -it  mongo-test mongo

OCI runtime exec failed: exec failed: unable to start container process: exec: "mongo": executable file not found in $PATH: unknown

 异常原因:

OCI runtime exec failed: exec failed: unable to start container process: exec: "mongo": executable file not found in $PATH: unknown

官网解决方案:

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

mongo5.0以上的版本使用mongo来执行mongodb命令已经不支持了,你需要改用mongosh来替代mongo!

OCI runtime exec failed: exec failed: unable to start container process: exec: "mongo": executable file not found in $PATH: unknown