Busybox

简介

Busybox - Linux 瑞士军刀

BusyBox 是一个集成了一百多个最常用 Linux 命令和工具(如 catechogrepmounttelnet 等)的精简工具箱,它只需要几 MB 的大小,很方便进行各种快速验证,被誉为“Linux 系统的瑞士军刀”。

BusyBox 可运行于多款 POSIX 环境的操作系统中,如 Linux(包括 Android)、HurdFreeBSD 等。

获取官方镜像

Docker Hub 中搜索 busybox 相关的镜像。

  1. $ docker search busybox
  2. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  3. busybox Busybox base image. 755 [OK]
  4. progrium/busybox 63 [OK]
  5. radial/busyboxplus Full-chain, Internet enabled, busybox made... 11 [OK]
  6. odise/busybox-python 3 [OK]
  7. multiarch/busybox multiarch ports of ubuntu-debootstrap 2 [OK]
  8. azukiapp/busybox This image is meant to be used as the base... 2 [OK]
  9. ...

读者可以看到最受欢迎的镜像同时带有 OFFICIAL 标记,说明它是官方镜像。用户使用 docker pull 指令下载 busybox:latest 镜像:

  1. $ docker pull busybox:latest
  2. latest: Pulling from library/busybox
  3. 5c4213be9af9: Pull complete
  4. Digest: sha256:c6b45a95f932202dbb27c31333c4789f45184a744060f6e569cc9d2bf1b9ad6f
  5. Status: Downloaded newer image for busybox:latest
  6. docker.io/library/busybox:latest

下载后,可以看到 busybox 镜像只有 2.433 MB

  1. $ docker image ls
  2. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  3. busybox latest e72ac664f4f0 6 weeks ago 2.433 MB

运行 busybox

启动一个 busybox 容器,并在容器中执行 grep 命令。

  1. $ docker run -it busybox
  2. / # grep
  3. BusyBox v1.22.1 (2014-05-22 23:22:11 UTC) multi-call binary.
  4. Usage: grep [-HhnlLoqvsriwFE] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...
  5. Search for PATTERN in FILEs (or stdin)
  6. -H Add 'filename:' prefix
  7. -h Do not add 'filename:' prefix
  8. -n Add 'line_no:' prefix
  9. -l Show only names of files that match
  10. -L Show only names of files that don't match
  11. -c Show only count of matching lines
  12. -o Show only the matching part of line
  13. -q Quiet. Return 0 if PATTERN is found, 1 otherwise
  14. -v Select non-matching lines
  15. -s Suppress open and read errors
  16. -r Recurse
  17. -i Ignore case
  18. -w Match whole words only
  19. -x Match whole lines only
  20. -F PATTERN is a literal (not regexp)
  21. -E PATTERN is an extended regexp
  22. -m N Match up to N times per file
  23. -A N Print N lines of trailing context
  24. -B N Print N lines of leading context
  25. -C N Same as '-A N -B N'
  26. -e PTRN Pattern to match
  27. -f FILE Read pattern from file

查看容器内的挂载信息。

  1. / # mount
  2. overlay on / type overlay (rw,relatime,lowerdir=/var/lib/docker/overlay2/l/BOTCI5RF24AMC4A2UWF4N6ZWFP:/var/lib/docker/overlay2/l/TWVP5T5DMKJGXZOROR7CAPWGFP,upperdir=/var/lib/docker/overlay2/801ef0bf6cce35288dbb8fe00a4f9cc47760444693bfdf339ed0bdcf926e12a3/diff,workdir=/var/lib/docker/overlay2/801ef0bf6cce35288dbb8fe00a4f9cc47760444693bfdf339ed0bdcf926e12a3/work)
  3. proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
  4. tmpfs on /dev type tmpfs (rw,nosuid,size=65536k,mode=755)
  5. devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
  6. sysfs on /sys type sysfs (ro,nosuid,nodev,noexec,relatime)
  7. tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,relatime,mode=755)
  8. cgroup on /sys/fs/cgroup/systemd type cgroup (ro,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd)
  9. cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (ro,nosuid,nodev,noexec,relatime,net_cls,net_prio)
  10. cgroup on /sys/fs/cgroup/freezer type cgroup (ro,nosuid,nodev,noexec,relatime,freezer)
  11. cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (ro,nosuid,nodev,noexec,relatime,cpu,cpuacct)
  12. cgroup on /sys/fs/cgroup/cpuset type cgroup (ro,nosuid,nodev,noexec,relatime,cpuset)
  13. cgroup on /sys/fs/cgroup/blkio type cgroup (ro,nosuid,nodev,noexec,relatime,blkio)
  14. cgroup on /sys/fs/cgroup/perf_event type cgroup (ro,nosuid,nodev,noexec,relatime,perf_event)
  15. cgroup on /sys/fs/cgroup/memory type cgroup (ro,nosuid,nodev,noexec,relatime,memory)
  16. cgroup on /sys/fs/cgroup/devices type cgroup (ro,nosuid,nodev,noexec,relatime,devices)
  17. cgroup on /sys/fs/cgroup/pids type cgroup (ro,nosuid,nodev,noexec,relatime,pids)
  18. mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
  19. shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=65536k)
  20. /dev/vda1 on /etc/resolv.conf type ext3 (rw,noatime,data=ordered)
  21. /dev/vda1 on /etc/hostname type ext3 (rw,noatime,data=ordered)
  22. /dev/vda1 on /etc/hosts type ext3 (rw,noatime,data=ordered)
  23. devpts on /dev/console type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
  24. proc on /proc/bus type proc (ro,relatime)
  25. proc on /proc/fs type proc (ro,relatime)
  26. proc on /proc/irq type proc (ro,relatime)
  27. proc on /proc/sys type proc (ro,relatime)
  28. proc on /proc/sysrq-trigger type proc (ro,relatime)
  29. tmpfs on /proc/acpi type tmpfs (ro,relatime)
  30. tmpfs on /proc/kcore type tmpfs (rw,nosuid,size=65536k,mode=755)
  31. tmpfs on /proc/keys type tmpfs (rw,nosuid,size=65536k,mode=755)
  32. tmpfs on /proc/timer_list type tmpfs (rw,nosuid,size=65536k,mode=755)
  33. tmpfs on /proc/sched_debug type tmpfs (rw,nosuid,size=65536k,mode=755)
  34. tmpfs on /sys/firmware type tmpfs (ro,relatime)

busybox 镜像虽然小巧,但包括了大量常见的 Linux 命令,读者可以用它快速熟悉 Linux 命令。

相关资源