一次bash: docker: command not found bash: yum: command not found的解决

周青的日常问题记录

项目场景:

学习硅谷电商毕设项目_微服务版本,建站练手,在测试mysql中docker exec进入容器sql语句


问题描述

docker exec bash后用\q退出mysql
在这里插入图片描述
再运行bash命令继续操作docker发现命令失效

bash: docker: command not found bash

想service docker start启动docker但是

docker: unrecognized service

把服务器重启了一下,到这一步还是不行。

找了找办法要卸载重装但yum竟然也用不了

bash: yum: command not found

原因分析:

用\q退出mysql后仍当前在exec执行docker容器的bash中,故不能识别除基础bash外的linux命令。

command not found状态下用户显示是:root@e30eeb49974d:/#

root@e30eeb49974d:/# docker -v
bash: docker: command not found

正常状态下用户显示是:[root@VM-24-10-centos ~]#

[root@VM-24-10-centos ~]# docker -v
Docker version 20.10.23, build 7155243

解决方案:

用exit退出exec bash

root@e30eeb49974d:/# exit
exit
[root@VM-24-10-centos ~]# 


后记废话

以下为解决本问题时走的弯路,并无阅读价值,仅做面向自己的记录。

弯路第一阶段

意识到真正原因前,我以为是腾讯云不行。。。查了一下【1】【2】,发现是因为系统的环境变量没有正确配置造成的,想要解决需要手动配置变量,我不知道还有多少命令也失效了,对Linux也不甚熟悉。不敢手动继续改,就想去腾讯云控制台重装了系统能不能解决。重装回来之后yum能用了
在这里插入图片描述

重新安装docker,在这里插入图片描述
但一用还是不行。重装系统不能解决问题。

[root@VM-24-10-centos ~]# systemctl start docker
[root@VM-24-10-centos ~]# docker-v
-bash: docker-v: 未找到命令
[root@VM-24-10-centos ~]# service docker start 
Redirecting to /bin/systemctl start docker.service

弯路第二阶段

最早搜索 bash: docker:command not found时看到过一句话劝大家最好把docker设置成开机自启。在《当提示Redirecting to /bin/systemctl stop docker.service请使用下列命令 启动与停止Docker》中看到了开机自启docker命令,尝试后暂时成功。

systemctl enable docker

运行后docker正常

[root@VM-24-10-centos ~]# docker -v
Docker version 20.10.23, build 7155243
[root@VM-24-10-centos ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

但走到exec bash时又回到老路上。。。

弯路第三阶段

断开连接又重新连上,发现用户提醒不同,才发现了问题根源。
在这里插入图片描述


End

猜你喜欢

转载自blog.csdn.net/two_brother_/article/details/128826780