在docker中执行某些命令的时候 docker bash: xxx : command not found 通用解决方案

  • 作者: 凯哥Java(公众号:凯哥Java)
  • Docker
  • 时间:2023-08-20 21:10
  • 2393人已阅读
简介 我们在使用docker的时候,有时需要使用某些命令,比如使用vim命令或者使用systemctl的时候提示commandnotfound。1:现象,如下图:2:原因饭呢西容器内没有安装相关服务的命令3:解决办法命令公式:apt-get update && apt-get install 需要的命令比如这里凯哥(微信公众号凯哥Java

🔔🔔好消息!好消息!🔔🔔

 如果您需要注册ChatGPT,想要升级ChatGPT4。凯哥可以代注册ChatGPT账号代升级ChatGPT4

有需要的朋友👉:微信号 kaigejava2022

我们在使用docker的时候,有时需要使用某些命令,比如使用vim命令或者使用systemctl的时候提示command not found。

1:现象,如下图:

f222997cf9df129bcdef474620c2152a.png

2:原因饭呢西

容器内没有安装相关服务的命令

3:解决办法

命令公式:

apt-get update && apt-get install 需要的命令

比如这里凯哥(微信公众号 凯哥Java:kaigejava)这里需要更新yum命令。套用上面的公式

apt-get update && apt-get install yum

执行,会询问是继续。如下图;

947b064b9d3d169aced954125c121bc8.png

输入Y。继续,然后会继续下载更新。

凯哥(微信公众号 凯哥Java:kaigejava)这里就记录一些常用的command not found命令在docker中怎么解决


(1)bash: ip: command not found

apt-get update && apt-get install -y iproute2

(2)bash: yum: command not found

apt-get update && apt-get install yum

(3)bash: ping: command not found

apt-get update && apt install iputils-ping


(4)bash: ifconfig: command not found

apt-get update && apt install net-tools


(5)bash: vi: command not found

apt-get update &&  apt-get install vim

(6)bash: route: command not found

apt-get update && apt-get install -y iproute2 && apt-get update && apt install net-tools

(7) bash: netstat: command not found

apt-get update && apt install net-tools

(8)bash: ps: command not found

apt-get update && apt-get install procps

(9)bash: top: command not found

apt-get update && apt-get install procps



TopTop