【Docker】Alpine镜像中安装telnet

Alpine镜像是一个基于Alpine Linux发行版构建的Docker镜像,具有以下特点和优势:

  • 小巧轻量:Alpine Linux的基础镜像非常小巧,通常只有几MB大小(例如,只有5 MB左右,对比Ubuntu系列镜像接近200 MB),这使得它启动更快,占用更少的磁盘空间。
  • 安全可靠:Alpine Linux专注于提供一个安全的操作系统,它采用了musl libc来替代glibc,musl libc被认为更加安全,且对于容器化应用来说,足够满足需求。
  • 易于定制:Alpine镜像提供了一个简单的基础环境,可以根据需要添加所需的软件包,定制自己的镜像。Alpine Linux使用了apk包管理工具,安装和卸载软件包非常方便。
  • 社区支持:Alpine Linux拥有一个活跃的社区,提供了大量的文档和支持。在Docker社区中,有很多基于Alpine镜像的开源项目和Dockerfile,可以方便地获取和使用。

Alpine镜像的广泛应用得益于其小巧、安全、易于定制和活跃的社区支持等特点,特别是在容器化应用场景下,它成为了首选的基础镜像。使用Alpine镜像可以带来多个好处,包括镜像下载速度加快,镜像安全性提高,主机之间的切换更方便,占用更少磁盘空间等。

此外,Alpine Linux提供了自己的包管理工具apk,使得用户可以通过apk命令直接查询和安装各种软件。Alpine镜像也适用于更多常用场景,是一个优秀的可以适用于生产的基础系统/环境。

Alpine镜像安装软件

Alpine镜像安装telnet

Alpine镜像中的telnet在3.7版本后被转移至busybox-extras包中:

$ apk update

$ apk add busybox-extras

$telnet smtp.163.com 25   #telnet 确认指定端口是否开启

Alpine镜像安装MySQL客户端

$ apk add --no-cache mysql-client

BusyBox

BusyBox命令工具是一个面向嵌入式系统的工具集合,它提供了一个精简的Unix工具集合,包括了许多常用的命令和工具。

BusyBox的主要特点

  • 轻量级:BusyBox的可执行文件非常小巧,适用于资源受限的环境。
  • 功能强大:包含了许多常见的Unix命令,如ls、cat、cp、mv、rm等,用于文件和目录管理、网络管理、系统管理、软件包管理以及系统设置等。
  • 灵活性:提供了许多编译选项,可以根据需求选择需要的工具,并排除不需要的工具。
  • 兼容性:BusyBox的工具与传统的Unix工具具有相似的命令行接口和功能,可以方便地替代传统的Unix工具。

BusyBox的常用命令

BusyBox包含了许多常见的Unix命令,其中一些常见的命令包括:

  • ls:列出文件和目录。
  • cp:复制文件和目录。
  • mv:移动文件和目录。
  • rm:删除文件和目录。
  • cat:查看文件内容。
  • find:搜索文件和目录。
  • ifconfig、route:用于网络配置和路由表管理。
  • ps、top、kill:用于进程查看和管理。
  • tar、gzip:用于打包和压缩文件。
  • mount、umount:用于挂载和卸载文件系统。

busybox提供的所有命令如下:

$ busybox
BusyBox v1.36.1 (2023-11-07 18:53:09 UTC) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2015.
Licensed under GPLv2. See source distribution for detailed
copyright notices.

Usage: busybox [function [arguments]...]
   or: busybox --list[-full]
   or: busybox --install [-s] [DIR]
   or: function [arguments]...

        BusyBox is a multi-call binary that combines many common Unix
        utilities into a single executable.  Most people will create a
        link to busybox for each function they wish to use and BusyBox
        will act like whatever it was invoked as.

Currently defined functions:
        [, [[, acpid, add-shell, addgroup, adduser, adjtimex, arch, arp, arping, ash, awk, base64, basename, bbconfig, bc, beep, blkdiscard,
        blkid, blockdev, brctl, bunzip2, bzcat, bzip2, cal, cat, chattr, chgrp, chmod, chown, chpasswd, chroot, chvt, cksum, clear, cmp, comm,
        cp, cpio, crond, crontab, cryptpw, cut, date, dc, dd, deallocvt, delgroup, deluser, depmod, df, diff, dirname, dmesg, dnsdomainname,
        dos2unix, du, dumpkmap, echo, egrep, eject, env, ether-wake, expand, expr, factor, fallocate, false, fatattr, fbset, fbsplash, fdflush,
        fdisk, fgrep, find, findfs, flock, fold, free, fsck, fstrim, fsync, fuser, getopt, getty, grep, groups, gunzip, gzip, halt, hd, head,
        hexdump, hostid, hostname, hwclock, id, ifconfig, ifdown, ifenslave, ifup, init, inotifyd, insmod, install, ionice, iostat, ip, ipaddr,
        ipcalc, ipcrm, ipcs, iplink, ipneigh, iproute, iprule, iptunnel, kbd_mode, kill, killall, killall5, klogd, last, less, link, linux32,
        linux64, ln, loadfont, loadkmap, logger, login, logread, losetup, ls, lsattr, lsmod, lsof, lsusb, lzcat, lzma, lzop, lzopcat, makemime,
        md5sum, mdev, mesg, microcom, mkdir, mkdosfs, mkfifo, mkfs.vfat, mknod, mkpasswd, mkswap, mktemp, modinfo, modprobe, more, mount,
        mountpoint, mpstat, mv, nameif, nanddump, nandwrite, nbd-client, nc, netstat, nice, nl, nmeter, nohup, nologin, nproc, nsenter,
        nslookup, ntpd, od, openvt, partprobe, passwd, paste, pgrep, pidof, ping, ping6, pipe_progress, pivot_root, pkill, pmap, poweroff,
        printenv, printf, ps, pscan, pstree, pwd, pwdx, raidautorun, rdate, rdev, readahead, readlink, realpath, reboot, reformime,
        remove-shell, renice, reset, resize, rev, rfkill, rm, rmdir, rmmod, route, run-parts, sed, sendmail, seq, setconsole, setfont,
        setkeycodes, setlogcons, setpriv, setserial, setsid, sh, sha1sum, sha256sum, sha3sum, sha512sum, showkey, shred, shuf, slattach, sleep,
        sort, split, stat, strings, stty, su, sum, swapoff, swapon, switch_root, sync, sysctl, syslogd, tac, tail, tar, tee, test, time,
        timeout, top, touch, tr, traceroute, traceroute6, tree, true, truncate, tty, ttysize, tunctl, udhcpc, udhcpc6, umount, uname, unexpand,
        uniq, unix2dos, unlink, unlzma, unlzop, unshare, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, vlock, volname, watch,
        watchdog, wc, wget, which, who, whoami, whois, xargs, xxd, xzcat, yes, zcat, zcip

busybox-extras提供的所有命令如下:

$ busybox-extras
BusyBox v1.36.1 (2024-06-12 06:28:12 UTC) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2015.
Licensed under GPLv2. See source distribution for detailed
copyright notices.

Usage: busybox [function [arguments]...]
   or: busybox --list[-full]
   or: busybox --install [-s] [DIR]
   or: function [arguments]...

        BusyBox is a multi-call binary that combines many common Unix
        utilities into a single executable.  Most people will create a
        link to busybox for each function they wish to use and BusyBox
        will act like whatever it was invoked as.

Currently defined functions:
        arch, conspy, dnsd, dumpleases, fakeidentd, ftpd, ftpget, ftpput, httpd, inetd, readahead, tcpsvd, telnet, telnetd, tftp, tftpd,
        udhcpd

BusyBox的优缺点

优点:轻量级、功能强大、灵活性和兼容性好。
缺点:由于BusyBox的设计目标是提供一个精简的工具集,因此某些高级功能可能不支持;对于不熟悉BusyBox的用户来说,可能需要一些时间来适应其命令行接口和工具的使用方式。

总的来说,BusyBox是一个在嵌入式系统和资源受限环境中广泛使用的工具集合,它为用户提供了轻量级、功能强大和灵活的命令行工具集。

### 如何在 Docker安装和配置 Alpine Linux #### 安装 Alpine Linux 镜像 要开始使用 Alpine Linux,在本地环境中首先需要拉取官方提供的镜像。通过执行如下命令可以从 Docker Hub 获取最新版本的 Alpine Linux: ```bash docker pull alpine:latest ``` 此操作会下载一个非常精简的基础操作系统映像到主机上,该映像仅包含运行基本命令所需的内容[^3]。 #### 启动交互式的 Alpine Linux 容器 为了进入一个临时性的、带有 shell 访问权限的容器实例,可利用下面这条指令创建并启动一个新的容器: ```bash docker run -it --rm alpine:latest /bin/sh ``` 上述命令中的 `-it` 参数允许用户与新启动的容器建立交互连接;而 `--rm` 则表示一旦退出当前 session,则自动清理掉这个容器实例。最后部分 `/bin/sh` 是指定容器内默认使用的 Shell 类型[^1]。 #### 在 Alpine安装额外软件包 由于 Alpine 使用的是不同于其他主流发行版的独特包管理系统 apk (Alpine Package Keeper),因此当想要向其中添加新的应用程序或库文件时,应当遵循特定语法来进行安装工作。例如,如果打算让容器支持 telnet 功能的话,那么就需要先更新索引再安装相应的客户端程序: ```bash # 更新软件源列表 apk update # 安装telnet客户端 apk add busybox-extras ``` 这里值得注意的一点是,因为某些常用工具可能并未被直接打包成独立的应用形式存在,所以有时不得不借助于一些集合性质的大包来间接实现目的,就像上面例子中提到的那样——busybox-extras 实际包含了多个小型实用程序在内的综合套件。 #### 创建自定义镜像保存更改 假设已经完成了必要的设置调整,并希望将这些改动永久保留下来以便日后重复利用,这时可以通过提交现有状态的方式生成一份全新的镜像副本。具体做法是在目标容器仍然处于活动状态下发出 commit 请求: ```bash docker commit <container_id> my_alpine_image:tagname ``` 这里的 `<container_id>` 应替换为实际正在工作的那个容器 ID 或名称;my_alpine_image 及 tagname 用户可根据个人喜好自行命名[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

morris131

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

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

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

打赏作者

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

抵扣说明:

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

余额充值