docker容器中bash: top: command not found的解决方法
新部署了一个MySQL的docker容器,插入10万测试数据时,想看下内存和CPU的占用情况,进入容器后运行top,报错bash: top: command not found,docker果然是最简形式,没有多余的东西。
那就apt-get update一下呗,继续报错
root@ad7556******:/# apt-get update
Err:1 http://deb.debian.org/debian buster InRelease
Temporary failure resolving 'deb.debian.org'
Err:2 http://security.debian.org/debian-security buster/updates InRelease
Temporary failure resolving 'security.debian.org'
Err:3 http://repo.mysql.com/apt/debian buster InRelease
Temporary failure resolving 'repo.mysql.com'
Err:4 http://deb.debian.org/debian buster-updates InRelease
Temporary failure resolving 'deb.debian.org'
Reading package lists... Done
W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://repo.mysql.com/apt/debian/dists/buster/InRelease Temporary failure resolving 'repo.mysql.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
需要修改获取包的地址
1、切换到 apt主目录
cd /etc/apt/
2、备份一下source.list
cp source.list source.list_backup
3、修改source.list,即apt源列表
echo "deb http://mirrors.163.com/debian stretch main">>sources.list
echo "deb http://security.debian.org/debian-security stretch/updates main">>sources.list
echo "deb http://mirrors.163.com/debian stretch-updates main">>sources.list
再运行,继续报错
root@ad75565******:/etc/apt# apt-get update
Err:1 http://security.debian.org/debian-security buster/updates InRelease
Temporary failure resolving 'security.debian.org'
Err:2 http://mirrors.aliyun.com/debian-security buster/updates InRelease
Temporary failure resolving 'mirrors.aliyun.com'
Err:3 http://repo.mysql.com/apt/debian buster InRelease
Temporary failure resolving 'repo.mysql.com'
Err:4 http://deb.debian.org/debian buster InRelease
Temporary failure resolving 'deb.debian.org'
Err:5 http://deb.debian.org/debian buster-updates InRelease
Temporary failure resolving 'deb.debian.org'
Reading package lists... Done
W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://mirrors.aliyun.com/debian-security/dists/buster/updates/InRelease Temporary failure resolving 'mirrors.aliyun.com'
W: Failed to fetch http://repo.mysql.com/apt/debian/dists/buster/InRelease Temporary failure resolving 'repo.mysql.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
想ping一下外面的域名看通不通的,报bash: ping: command not found
查资料得,要修改docker的dns
vim /etc/docker/daemon.json
编辑信息:
{
"dns": ["202.96.209.5","8.8.8.8"]
}
重启Docker服务
systemctl daemon-reload
systemctl restart docker
这次update成功了
root@ad7556******:/# apt-get update
Get:1 http://mirrors.aliyun.com/debian-security buster/updates InRelease [65.4 kB]
Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:3 http://repo.mysql.com/apt/debian buster InRelease [21.5 kB]
Get:4 http://mirrors.aliyun.com/debian-security buster/updates/main Sources [140 kB]
Get:5 http://repo.mysql.com/apt/debian buster/mysql-5.7 amd64 Packages [5668 B]
Get:6 http://security.debian.org/debian-security buster/updates/main amd64 Packages [234 kB]
Get:7 http://deb.debian.org/debian buster InRelease [121 kB]
Get:8 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:9 http://deb.debian.org/debian buster/main amd64 Packages [7906 kB]
Get:9 http://deb.debian.org/debian buster/main amd64 Packages [7906 kB]
Get:10 http://deb.debian.org/debian buster-updates/main amd64 Packages [7868 B]
Fetched 6835 kB in 9min 31s (12.0 kB/s)
Reading package lists... Done
满以为离成功很近,谁知
root@ad7556******:/etc/apt# apt-get install -y top
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package top
查看docker容器的linux版本才知道
root@ad7556592188:/etc/apt# cat /etc/issue
Debian GNU/Linux 10 \n \l
不支持top命令
直接运行
apt-get install busybox
busybox top
期待以久的界面出来了
Mem: 880952K used, 114732K free, 0K shrd, 47K buff, 94572469032272K cached
CPU: 0% usr 0% sys 0% nic 99% idle 0% io 0% irq 0% sirq
Load average: 0.01 0.07 0.10 3/217 3352
PID PPID USER STAT VSZ %VSZ %CPU COMMAND
1 0 mysql S 1089m 112% 0% mysqld
72 0 root S 3988 0% 0% bash
3352 72 root R 3008 0% 0% busybox top
可以直接输入top就运行吗?可以
root@ad7556******:/etc/apt# cd /bin
root@ad7556******:/bin# ln -s busybox top
root@ad7556******:/bin# top
Mem: 880952K used, 114732K free, 0K shrd, 0K buff, 94748724648384K cached
CPU: 0% usr 0% sys 0% nic 100% idle 0% io 0% irq 0% sirq
Load average: 0.00 0.05 0.10 3/217 3354
PID PPID USER STAT VSZ %VSZ %CPU COMMAND
1 0 mysql S 1089m 112% 0% mysqld
72 0 root S 3988 0% 0% bash
3354 72 root R 2924 0% 0% top
终于解决,希望对大家有帮助哈~~
还没有评论,来说两句吧...