docker 容器中安装常见工具

常用工具安装

查找 netstat 命令由哪个安装包提供

$ yum whatprovides /bin/netstat
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
Repo : base
Matched from:
Filename : /bin/netstat

安装 net-tools

yum install -y net-tools
apt-get install -y net-tools

安装 ping 命令

$ yum whatprovides /bin/ping
iputils-20160308-10.el7.x86_64 : Network monitoring tools including ping
Repo : base
Matched from:
Filename : /bin/ping


$ apt-cache search iputils
iputils-arping - Tool to send ICMP echo requests to an ARP address
iputils-clockdiff - Measure the time difference between networked computers
iputils-ping - Tools to test the reachability of network hosts
iputils-tracepath - Tools to trace the network path to a remote host

apt-get install -y iputils-ping

安装 ps 命令

apt-get install procps

安装 ip 命令

$ yum whatprovides /usr/sbin/ip
iproute-4.11.0-30.el7.x86_64 : Advanced IP routing and network device configuration tools
Repo : base
Matched from:
Filename : /usr/sbin/ip
apt-get install iproute2

sshd 安装

Dcokerfile
FROM centos:centos7.9.2009

RUN yum install -y openssh openssh-server net-tools \
&& ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N '' \
&& ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' \
&& ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N ''

CMD /sbin/sshd -D

sshd -D : -D 选项使 sshd 进程一直保持在前台运行,否则容器启动会会因为 sshd 运行结束而立即终止