Doker提供的ubuntu鏡像非常干凈,大小只有63.1MB,沒有常見的一些基本庫。

進(jìn)入ubuntu容器中查找不到ifconfig,ping,vim等基本命令。
test01@test:~$ docker run -it --name version1 ubuntu:18.04 /bin/bash
root@e63d89aab255:/# ifconfig
bash: ifconfig: command not found
root@e63d89aab255:/# ping www.baidu.com
bash: ping: command not found
root@e63d89aab255:/# ^C
root@e63d89aab255:/# vim
bash: vim: command not found
root@e63d89aab255:/#

通過apt-get命令進(jìn)行安裝。
root@e63d89aab255:/# apt-get update
root@e63d89aab255:/# apt install net-tools 安裝ifconfig
root@e63d89aab255:/# apt install iputils-ping 安裝ping



【注】:
net-tools包含:arp, ifconfig, netstat, rarp , nameif, route這幾個(gè)工具。
測試是否成功
root@e63d89aab255:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 12363 bytes 25090342 (25.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8626 bytes 473222 (473.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

原文鏈接:
Docker運(yùn)行ubuntu容器無ifconfig和ping等命令 - 知乎 (zhihu.com)
Docker運(yùn)行ubuntu容器無ifconfig和ping等命令 (qq.com)