Docker容器中使用PING命令报错:bash: ping: command not found

Docker容器中使用PING命令报错:bash: ping: command not found

在Docker容器中想要ping另外一个容器,比如是建立链接的源容器,却提示找不到ping命令。

root@dcad73196349:/# ping source
bash: ping: command not found

解决方法

apt-get update
root@dcad73196349:/# apt-get update
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]    
Get:2 http://deb.debian.org/debian buster InRelease [121 kB]             
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]                                                                                                     
Get:4 http://security.debian.org/debian-security buster/updates/main amd64 Packages [251 kB]                                                                              
Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7906 kB]                                                                                                                                                                                        
Get:6 http://deb.debian.org/debian buster-updates/main amd64 Packages [7856 B]                                                                                            
Fetched 6790 kB in 21min 48s (5193 B/s)                                                                                                                                   
Reading package lists... Done
apt install iputils-ping
root@dcad73196349:/# apt install iputils-ping
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libcap2 libcap2-bin libpam-cap
The following NEW packages will be installed:
  iputils-ping libcap2 libcap2-bin libpam-cap
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 104 kB of archives.
After this operation, 319 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://deb.debian.org/debian buster/main amd64 libcap2 amd64 1:2.25-2 [17.6 kB]
Get:2 http://deb.debian.org/debian buster/main amd64 iputils-ping amd64 3:20180629-2+deb10u1 [43.3 kB]
Get:3 http://deb.debian.org/debian buster/main amd64 libcap2-bin amd64 1:2.25-2 [28.8 kB]                                                                                 
Get:4 http://deb.debian.org/debian buster/main amd64 libpam-cap amd64 1:2.25-2 [14.3 kB]                                                                                  
Fetched 104 kB in 7s (14.8 kB/s)                                                                                                                                          
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libcap2:amd64.
(Reading database ... 7631 files and directories currently installed.)
Preparing to unpack .../libcap2_1%3a2.25-2_amd64.deb ...
Unpacking libcap2:amd64 (1:2.25-2) ...
Selecting previously unselected package iputils-ping.
Preparing to unpack .../iputils-ping_3%3a20180629-2+deb10u1_amd64.deb ...
Unpacking iputils-ping (3:20180629-2+deb10u1) ...
Selecting previously unselected package libcap2-bin.
Preparing to unpack .../libcap2-bin_1%3a2.25-2_amd64.deb ...
Unpacking libcap2-bin (1:2.25-2) ...
Selecting previously unselected package libpam-cap:amd64.
Preparing to unpack .../libpam-cap_1%3a2.25-2_amd64.deb ...
Unpacking libpam-cap:amd64 (1:2.25-2) ...
Setting up libcap2:amd64 (1:2.25-2) ...
Setting up libcap2-bin (1:2.25-2) ...
Setting up libpam-cap:amd64 (1:2.25-2) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.28.1 /usr/local/share/perl/5.28.1 /usr/lib/x86_64-linux-gnu/perl5/5.28 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.28 /usr/share/perl/5.28 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up iputils-ping (3:20180629-2+deb10u1) ...
Processing triggers for libc-bin (2.28-10) ...
apt install net-tools
root@dcad73196349:/# apt install net-tools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  net-tools
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 248 kB of archives.
After this operation, 1002 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian buster/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1 [248 kB]
Fetched 248 kB in 28s (8991 B/s)                                                                                                                                          
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package net-tools.
(Reading database ... 7671 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1_amd64.deb ...
Unpacking net-tools (1.60+git20180626.aebd88e-1) ...
Setting up net-tools (1.60+git20180626.aebd88e-1) ...

之后就可以使用ping命令了。

root@dcad73196349:/# ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.031 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.051 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.044 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.050 ms
root@dcad73196349:/# ping source
PING source (172.18.0.13) 56(84) bytes of data.
64 bytes from source (172.18.0.13): icmp_seq=1 ttl=64 time=0.142 ms
64 bytes from source (172.18.0.13): icmp_seq=2 ttl=64 time=0.070 ms
64 bytes from source (172.18.0.13): icmp_seq=3 ttl=64 time=0.061 ms
64 bytes from source (172.18.0.13): icmp_seq=4 ttl=64 time=0.058 ms
64 bytes from source (172.18.0.13): icmp_seq=5 ttl=64 time=0.066 ms
64 bytes from source (172.18.0.13): icmp_seq=6 ttl=64 time=0.059 ms

这样就没问题了。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ITKaven

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值