解决:Command ‘mongo‘ not found, but can be installed with
目录
问题
如果你想保证自己服务镜像足够小,那就要保证保证基础镜像尽量干净,但是这又会出现另一个问题,启动的容器内经常会遇到工具缺失的问题,需要手动安装。
这不,今天自己就遇到了。在新启动的容器内使用 mongo 命令连接数据库的时候,遇到了如下报错:
Command 'mongo' not found, but can be installed with:
apt install mongodb-clients
类似问题的报错截图如下:
解决
解决这个问题也非常简单,只需要安装 mongodb 客户端即可。但是需要注意当前系统类型,使用正确的包管理工具,本机安装命令如下:
apt install mongodb-clients
或者
apt-get install mongodb-clients
执行过程如下:
root@al-bj-boom-hb-backstage-01:~/bag# apt-get install mongodb-clientsReading package lists... DoneBuilding dependency treeReading state information... DoneThe following additional packages will be installed: libboost-filesystem1.71.0 libboost-iostreams1.71.0 libboost-program-options1.71.0 libgoogle-perftools4 libpcap0.8 libpcrecpp0v5 libsasl2-2 libsasl2-modules libsasl2-modules-db libsnappy1v5 libstemmer0d libtcmalloc-minimal4 libunwind8 libyaml-cpp0.6 mongo-toolsSuggested packages: libsasl2-modules-gssapi-mit | libsasl2-modules-gssapi-heimdal libsasl2-modules-ldap libsasl2-modules-otp libsasl2-modules-sqlThe following NEW packages will be installed: libboost-filesystem1.71.0 libboost-iostreams1.71.0 libboost-program-options1.71.0 libgoogle-perftools4 libpcap0.8 libpcrecpp0v5 libsasl2-2 libsasl2-modules libsasl2-modules-db libsnappy1v5 libstemmer0d libtcmalloc-minimal4 libunwind8 libyaml-cpp0.6 mongo-tools mongodb-clients0 upgraded, 16 newly installed, 0 to remove and 19 not upgraded.Need to get 35.5 MB of archives.After this operation, 157 MB of additional disk space will be used.Do you want to continue? [Y/n] yGet:1 http://archive.ubuntu.com/ubuntu focal/main amd64 libpcap0.8 amd64 1.9.1-3 [128 kB]Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 libboost-filesystem1.71.0 amd64 1.71.0-6ubuntu6 [242 kB]Get:3 http://archive.ubuntu.com/ubuntu focal/main amd64 libboost-iostreams1.71.0 amd64 1.71.0-6ubuntu6 [237 kB]Get:4 http://archive.ubuntu.com/ubuntu focal/main amd64 libboost-program-options1.71.0 amd64 1.71.0-6ubuntu6 [342 kB]Get:5 http://archive.ubuntu.com/ubuntu focal/main amd64 libtcmalloc-minimal4 amd64 2.7-1ubuntu2 [93.0 kB]Get:6 http://archive.ubuntu.com/ubuntu focal/main amd64 libunwind8 amd64 1.2.1-9build1 [47.6 kB]Get:7 http://archive.ubuntu.com/ubuntu focal/main amd64 libgoogle-perftools4 amd64 2.7-1ubuntu2 [195 kB]Get:8 http://archive.ubuntu.com/ubuntu focal/main amd64 libpcrecpp0v5 amd64 2:8.39-12build1 [15.5 kB]Get:9 http://archive.ubuntu.com/ubuntu focal/main amd64 libsasl2-modules-db amd64 2.1.27+dfsg-2 [14.9 kB]Get:10 http://archive.ubuntu.com/ubuntu focal/main amd64 libsasl2-2 amd64 2.1.27+dfsg-2 [49.3 kB]Get:11 http://archive.ubuntu.com/ubuntu focal/main amd64 libsasl2-modules amd64 2.1.27+dfsg-2 [49.1 kB]Get:12 http://archive.ubuntu.com/ubuntu focal/main amd64 libstemmer0d amd64 0+svn585-2 [61.7 kB]Get:13 http://archive.ubuntu.com/ubuntu focal/main amd64 libyaml-cpp0.6 amd64 0.6.2-4ubuntu1 [124 kB]Get:14 http://archive.ubuntu.com/ubuntu focal/universe amd64 mongo-tools amd64 3.6.3-0ubuntu1 [12.3 MB]Get:15 http://archive.ubuntu.com/ubuntu focal/main amd64 libsnappy1v5 amd64 1.1.8-1build1 [16.7 kB]Get:16 http://archive.ubuntu.com/ubuntu focal/universe amd64 mongodb-clients amd64 1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5 [21.6 MB]Fetched 35.5 MB in 4min 20s (137 kB/s)debconf: delaying package configuration, since apt-utils is not installedSelecting previously unselected package libpcap0.8:amd64.(Reading database ... 6374 files and directories currently installed.)Preparing to unpack .../00-libpcap0.8_1.9.1-3_amd64.deb ...Unpacking libpcap0.8:amd64 (1.9.1-3) ...Selecting previously unselected package libboost-filesystem1.71.0:amd64.Preparing to unpack .../01-libboost-filesystem1.71.0_1.71.0-6ubuntu6_amd64.deb ...Unpacking libboost-filesystem1.71.0:amd64 (1.71.0-6ubuntu6) ...Selecting previously unselected package libboost-iostreams1.71.0:amd64.Preparing to unpack .../02-libboost-iostreams1.71.0_1.71.0-6ubuntu6_amd64.deb ...Unpacking libboost-iostreams1.71.0:amd64 (1.71.0-6ubuntu6) ...Selecting previously unselected package libboost-program-options1.71.0:amd64.Preparing to unpack .../03-libboost-program-options1.71.0_1.71.0-6ubuntu6_amd64.deb ...Unpacking libboost-program-options1.71.0:amd64 (1.71.0-6ubuntu6) ...Selecting previously unselected package libtcmalloc-minimal4:amd64.Preparing to unpack .../04-libtcmalloc-minimal4_2.7-1ubuntu2_amd64.deb ...Unpacking libtcmalloc-minimal4:amd64 (2.7-1ubuntu2) ...Selecting previously unselected package libunwind8:amd64.Preparing to unpack .../05-libunwind8_1.2.1-9build1_amd64.deb ...Unpacking libunwind8:amd64 (1.2.1-9build1) ...Selecting previously unselected package libgoogle-perftools4:amd64.Preparing to unpack .../06-libgoogle-perftools4_2.7-1ubuntu2_amd64.deb ...Unpacking libgoogle-perftools4:amd64 (2.7-1ubuntu2) ...Selecting previously unselected package libpcrecpp0v5:amd64.Preparing to unpack .../07-libpcrecpp0v5_2%3a8.39-12build1_amd64.deb ...Unpacking libpcrecpp0v5:amd64 (2:8.39-12build1) ...Selecting previously unselected package libsasl2-modules-db:amd64.Preparing to unpack .../08-libsasl2-modules-db_2.1.27+dfsg-2_amd64.deb ...Unpacking libsasl2-modules-db:amd64 (2.1.27+dfsg-2) ...Selecting previously unselected package libsasl2-2:amd64.Preparing to unpack .../09-libsasl2-2_2.1.27+dfsg-2_amd64.deb ...Unpacking libsasl2-2:amd64 (2.1.27+dfsg-2) ...Selecting previously unselected package libsasl2-modules:amd64.Preparing to unpack .../10-libsasl2-modules_2.1.27+dfsg-2_amd64.deb ...Unpacking libsasl2-modules:amd64 (2.1.27+dfsg-2) ...Selecting previously unselected package libstemmer0d:amd64.Preparing to unpack .../11-libstemmer0d_0+svn585-2_amd64.deb ...Unpacking libstemmer0d:amd64 (0+svn585-2) ...Selecting previously unselected package libyaml-cpp0.6:amd64.Preparing to unpack .../12-libyaml-cpp0.6_0.6.2-4ubuntu1_amd64.deb ...Unpacking libyaml-cpp0.6:amd64 (0.6.2-4ubuntu1) ...Selecting previously unselected package mongo-tools.Preparing to unpack .../13-mongo-tools_3.6.3-0ubuntu1_amd64.deb ...Unpacking mongo-tools (3.6.3-0ubuntu1) ...Selecting previously unselected package libsnappy1v5:amd64.Preparing to unpack .../14-libsnappy1v5_1.1.8-1build1_amd64.deb ...Unpacking libsnappy1v5:amd64 (1.1.8-1build1) ...Selecting previously unselected package mongodb-clients.Preparing to unpack .../15-mongodb-clients_1%3a3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5_amd64.deb ...Unpacking mongodb-clients (1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5) ...Setting up libpcrecpp0v5:amd64 (2:8.39-12build1) ...Setting up libsasl2-modules:amd64 (2.1.27+dfsg-2) ...Setting up libtcmalloc-minimal4:amd64 (2.7-1ubuntu2) ...Setting up libboost-filesystem1.71.0:amd64 (1.71.0-6ubuntu6) ...Setting up libunwind8:amd64 (1.2.1-9build1) ...Setting up libboost-iostreams1.71.0:amd64 (1.71.0-6ubuntu6) ...Setting up libsnappy1v5:amd64 (1.1.8-1build1) ...Setting up libsasl2-modules-db:amd64 (2.1.27+dfsg-2) ...Setting up libpcap0.8:amd64 (1.9.1-3) ...Setting up libyaml-cpp0.6:amd64 (0.6.2-4ubuntu1) ...Setting up libsasl2-2:amd64 (2.1.27+dfsg-2) ...Setting up mongo-tools (3.6.3-0ubuntu1) ...Setting up libstemmer0d:amd64 (0+svn585-2) ...Setting up libgoogle-perftools4:amd64 (2.7-1ubuntu2) ...Setting up libboost-program-options1.71.0:amd64 (1.71.0-6ubuntu6) ...Setting up mongodb-clients (1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5) ...Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
过程截图如下:
安装成功后,我们执行刚才的数据库连接命令:
mongo 127.0.0.1:27017
哈哈,连接成功了。
成功截图如下:
作者简介:😄大家好,我是 Data-Mining(liuzhen007),是一位音视频技术爱好者,前后就职于传统广电巨头和音视频互联网公司,具有丰富的音视频直播和点播相关经验,对 WebRTC、FFmpeg 和 Electron 有非常深入的了解,😄公众号:玩转音视频。同时也是 CSDN 博客专家、华为云社区云享专家、签约作者,欢迎关注我分享更多干货!😄
版权声明: 本文为 InfoQ 作者【liuzhen007】的原创文章。
原文链接:【http://xie.infoq.cn/article/f8b5f568c54055a2bec22ebe7】。文章转载请联系作者。
评论