docker容器中bash: top: command not found的解决方法

你的名字 2022-12-15 11:15 268阅读 0赞

新部署了一个MySQL的docker容器,插入10万测试数据时,想看下内存和CPU的占用情况,进入容器后运行top,报错bash: top: command not found,docker果然是最简形式,没有多余的东西。

那就apt-get update一下呗,继续报错

  1. root@ad7556******:/# apt-get update
  2. Err:1 http://deb.debian.org/debian buster InRelease
  3. Temporary failure resolving 'deb.debian.org'
  4. Err:2 http://security.debian.org/debian-security buster/updates InRelease
  5. Temporary failure resolving 'security.debian.org'
  6. Err:3 http://repo.mysql.com/apt/debian buster InRelease
  7. Temporary failure resolving 'repo.mysql.com'
  8. Err:4 http://deb.debian.org/debian buster-updates InRelease
  9. Temporary failure resolving 'deb.debian.org'
  10. Reading package lists... Done
  11. W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease Temporary failure resolving 'deb.debian.org'
  12. W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease Temporary failure resolving 'security.debian.org'
  13. W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease Temporary failure resolving 'deb.debian.org'
  14. W: Failed to fetch http://repo.mysql.com/apt/debian/dists/buster/InRelease Temporary failure resolving 'repo.mysql.com'
  15. W: Some index files failed to download. They have been ignored, or old ones used instead.

需要修改获取包的地址
1、切换到 apt主目录

  1. cd /etc/apt/

2、备份一下source.list

  1. cp source.list source.list_backup

3、修改source.list,即apt源列表

  1. echo "deb http://mirrors.163.com/debian stretch main">>sources.list
  2. echo "deb http://security.debian.org/debian-security stretch/updates main">>sources.list
  3. echo "deb http://mirrors.163.com/debian stretch-updates main">>sources.list

再运行,继续报错

  1. root@ad75565******:/etc/apt# apt-get update
  2. Err:1 http://security.debian.org/debian-security buster/updates InRelease
  3. Temporary failure resolving 'security.debian.org'
  4. Err:2 http://mirrors.aliyun.com/debian-security buster/updates InRelease
  5. Temporary failure resolving 'mirrors.aliyun.com'
  6. Err:3 http://repo.mysql.com/apt/debian buster InRelease
  7. Temporary failure resolving 'repo.mysql.com'
  8. Err:4 http://deb.debian.org/debian buster InRelease
  9. Temporary failure resolving 'deb.debian.org'
  10. Err:5 http://deb.debian.org/debian buster-updates InRelease
  11. Temporary failure resolving 'deb.debian.org'
  12. Reading package lists... Done
  13. W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease Temporary failure resolving 'deb.debian.org'
  14. W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease Temporary failure resolving 'security.debian.org'
  15. W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease Temporary failure resolving 'deb.debian.org'
  16. W: Failed to fetch http://mirrors.aliyun.com/debian-security/dists/buster/updates/InRelease Temporary failure resolving 'mirrors.aliyun.com'
  17. W: Failed to fetch http://repo.mysql.com/apt/debian/dists/buster/InRelease Temporary failure resolving 'repo.mysql.com'
  18. W: Some index files failed to download. They have been ignored, or old ones used instead.

想ping一下外面的域名看通不通的,报bash: ping: command not found

查资料得,要修改docker的dns

  1. vim /etc/docker/daemon.json

编辑信息:

  1. {
  2. "dns": ["202.96.209.5","8.8.8.8"]
  3. }

重启Docker服务

  1. systemctl daemon-reload
  2. systemctl restart docker

这次update成功了

  1. root@ad7556******:/# apt-get update
  2. Get:1 http://mirrors.aliyun.com/debian-security buster/updates InRelease [65.4 kB]
  3. Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
  4. Get:3 http://repo.mysql.com/apt/debian buster InRelease [21.5 kB]
  5. Get:4 http://mirrors.aliyun.com/debian-security buster/updates/main Sources [140 kB]
  6. Get:5 http://repo.mysql.com/apt/debian buster/mysql-5.7 amd64 Packages [5668 B]
  7. Get:6 http://security.debian.org/debian-security buster/updates/main amd64 Packages [234 kB]
  8. Get:7 http://deb.debian.org/debian buster InRelease [121 kB]
  9. Get:8 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
  10. Get:9 http://deb.debian.org/debian buster/main amd64 Packages [7906 kB]
  11. Get:9 http://deb.debian.org/debian buster/main amd64 Packages [7906 kB]
  12. Get:10 http://deb.debian.org/debian buster-updates/main amd64 Packages [7868 B]
  13. Fetched 6835 kB in 9min 31s (12.0 kB/s)
  14. Reading package lists... Done

满以为离成功很近,谁知

  1. root@ad7556******:/etc/apt# apt-get install -y top
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. E: Unable to locate package top

查看docker容器的linux版本才知道

  1. root@ad7556592188:/etc/apt# cat /etc/issue
  2. Debian GNU/Linux 10 \n \l

不支持top命令
直接运行

  1. apt-get install busybox
  2. busybox top

期待以久的界面出来了

  1. Mem: 880952K used, 114732K free, 0K shrd, 47K buff, 94572469032272K cached
  2. CPU: 0% usr 0% sys 0% nic 99% idle 0% io 0% irq 0% sirq
  3. Load average: 0.01 0.07 0.10 3/217 3352
  4. PID PPID USER STAT VSZ %VSZ %CPU COMMAND
  5. 1 0 mysql S 1089m 112% 0% mysqld
  6. 72 0 root S 3988 0% 0% bash
  7. 3352 72 root R 3008 0% 0% busybox top

可以直接输入top就运行吗?可以

  1. root@ad7556******:/etc/apt# cd /bin
  2. root@ad7556******:/bin# ln -s busybox top
  3. root@ad7556******:/bin# top
  4. Mem: 880952K used, 114732K free, 0K shrd, 0K buff, 94748724648384K cached
  5. CPU: 0% usr 0% sys 0% nic 100% idle 0% io 0% irq 0% sirq
  6. Load average: 0.00 0.05 0.10 3/217 3354
  7. PID PPID USER STAT VSZ %VSZ %CPU COMMAND
  8. 1 0 mysql S 1089m 112% 0% mysqld
  9. 72 0 root S 3988 0% 0% bash
  10. 3354 72 root R 2924 0% 0% top

终于解决,希望对大家有帮助哈~~

发表评论

表情:
评论列表 (有 0 条评论,268人围观)

还没有评论,来说两句吧...

相关阅读