Insun Lee

命由己造,相由心生,世间万物皆是化相,心不动,万物皆不动,心不变,万物皆不变
Email insunsgmail.com
Country China
LocationHangZhou, ZheJiang

Alpine添加telnet(网络调试还是见文尾的busybox部分)


Alpine linux是个很小的系统,镜像大小通常只有5m左右,因此将其作为docker调试(测试)工具是个不错的选择。比如利用alpine进行网络调试(测试)。

但是默认的alpine并没有telnet工具,我们可以自行通过apk命令安装。注意,在Alpine中安装telnet,并不是apk add telnettelnet被移入子包busybox-extras中,因此安装命令为apk add busybox-extras

如果安装比较慢,可以将apk的镜像源修改为阿里云的:
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

然后再执行安装就很快了:

/ # apk add busybox-extras
fetch https://mirrors.aliyun.com/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://mirrors.aliyun.com/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
OK: 6 MiB in 15 packages

补充:
后来发现busybox作为网络调试工具是个更好的工具,其大小只有1.24M,关键是自带了telnet。

[host] $ docker run -it --rm --net=host busybox /bin/sh
/ # telnet localhost 5432
Connected to localhost
E)SERRORC08P01Mclient_login_timeoutConnection closed by foreign host
/ # ping www.baidu.com
PING www.baidu.com (180.101.49.11): 56 data bytes
64 bytes from 180.101.49.11: seq=0 ttl=50 time=11.758 ms
64 bytes from 180.101.49.11: seq=1 ttl=50 time=11.881 ms
64 bytes from 180.101.49.11: seq=2 ttl=50 time=11.839 ms
^C
--- www.baidu.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 11.758/11.826/11.881 ms

  • 分享:
评论

    • 博主

    说点什么