9.1 Busybox

时间 : 16-03-18 栏目 : linux精讲 作者 : 老薛 评论 : 0 点击 : 1,995 次

BusyBox是一个集成了一百多个最常用Linux命令和工具的软件工具箱,它在单一的可执行文件中提供了精简的Unix工具箱。BusyBox可运行于多款POSIX环境的操作系统中,如Linux(包括Android)、Hurd、FreeBSD等。
    BusyBox既包含了一些简单实用的工具,如cat和echo,也包含了一些更大、更复杂的工具、如grep、find、mount以及telnet。可以说,BusyBox是Linux系统的瑞士军刀。
使用官方镜像
    在DockerHub中搜索Busybox相关的镜像。
[root@dockers ~]# docker search busybox
INDEX       NAME                                       DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/busybox                          Busybox base image.                             560       [OK]       
docker.io   docker.io/progrium/busybox                                                                 59                   [OK]
docker.io   docker.io/radial/busyboxplus               Full-chain, Internet enabled, busybox made...   8                    [OK]
docker.io   docker.io/odise/busybox-python                                                             3                    [OK]
docker.io   docker.io/azukiapp/busybox                 This image is meant to be used as the base...   2                    [OK]
docker.io   docker.io/multiarch/busybox                multiarch ports of ubuntu-debootstrap           2                    [OK]
docker.io   docker.io/elektritter/busybox-teamspeak    Leightweight teamspeak3 container based on...   1                    [OK]
docker.io   docker.io/odise/busybox-curl                                                               1                    [OK]
docker.io   docker.io/ofayau/busybox-jvm               Prepare busybox to install a 32 bits JVM.       1                    [OK]
docker.io   docker.io/ofayau/busybox-libc32            Busybox with 32 bits (and 64 bits) libs         1                    [OK]
docker.io   docker.io/sequenceiq/busybox                                                               1                    [OK]
docker.io   docker.io/shingonoide/archlinux-busybox    Arch Linux, a lightweight and flexible Lin...   1                    [OK]
docker.io   docker.io/skomma/busybox-data              Docker image suitable for data volume cont...   1                    [OK]
docker.io   docker.io/socketplane/busybox                                                              1                    [OK]
docker.io   docker.io/container4armhf/armhf-busybox    Automated build of Busybox for armhf devic...   0                    [OK]
docker.io   docker.io/ggtools/busybox-ubuntu           Busybox ubuntu version with extra goodies       0                    [OK]
docker.io   docker.io/nikfoundas/busybox-confd         Minimal busybox based distribution of confd     0                    [OK]
docker.io   docker.io/openshift/busybox-http-app                                                       0                    [OK]
docker.io   docker.io/oveits/docker-nginx-busybox      This is a tiny NginX docker image based on...   0                    [OK]
docker.io   docker.io/powellquiring/busybox                                                            0                    [OK]
docker.io   docker.io/prom/busybox                     Prometheus Busybox Docker base images           0                    [OK]
docker.io   docker.io/sdurrheimer/prom-busybox         Moved to https://hub.docker.com/r/prom/bus...   0                    [OK]
docker.io   docker.io/shimomo/busybox                  BusyBox                                         0                    [OK]
docker.io   docker.io/simplexsys/busybox-cli-powered   Docker busybox images, with a few often us...   0                    [OK]
docker.io   docker.io/williamyeh/busybox-sh            Docker image for BusyBox's sh                   0                    [OK]
读者可以看到最受欢迎的镜像同时带有office1标记,说明它是官方镜像。
下面使用docker pull 命令下载这个镜像:
[root@dockers ~]# docker pull busybox
Using default tag: latest
Trying to pull repository docker.io/library/busybox ... latest: Pulling from library/busybox
c2ddbea624bd: Pull complete
f1e4b055fb65: Pull complete
Digest: sha256:0326ccfeddaaa974a3de8a21db451e782a306a46d5c597eee743c91a93d36bb7
Status: Downloaded newer image for docker.io/busybox:latest
如果不指定标签信息,则Docker会下载最新版本的Busybox镜像,可以看到Busybox镜像十分精巧,只有1.113MB。
[root@dockers ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED                  VIRTUAL SIZE
docker.io/busybox             latest              f1e4b055fb65        Less than a second ago   1.113 MB
运行Busybox
启动一个Busybox容器,并在容器中执行grep命令。
[root@dockers ~]# docker run -it busybox
/ # grep
BusyBox v1.24.1 (2016-03-15 19:38:13 UTC) multi-call binary.

Usage: grep [-HhnlLoqvsriwFE] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...

Search for PATTERN in FILEs (or stdin)

        -H      Add 'filename:' prefix
        -h      Do not add 'filename:' prefix
        -n      Add 'line_no:' prefix
        -l      Show only names of files that match
        -L      Show only names of files that don't match
        -c      Show only count of matching lines
        -o      Show only the matching part of line
        -q      Quiet. Return 0 if PATTERN is found, 1 otherwise
        -v      Select non-matching lines
        -s      Suppress open and read errors
        -r      Recurse
        -i      Ignore case
        -w      Match whole words only
        -x      Match whole lines only
        -F      PATTERN is a literal (not regexp)
        -E      PATTERN is an extended regexp
        -m N    Match up to N times per file
        -A N    Print N lines of trailing context
        -B N    Print N lines of leading context
        -C N    Same as '-A N -B N'
        -e PTRN Pattern to match
        -f FILE Read pattern from file
查看容器内的挂载信息。
/ # mount
rootfs on / type rootfs (rw)
/dev/mapper/docker-8:3-19689-6e2743fb3564ece71153b6f2365a702a05a4c1e54f4b06d442b7fdd4d245d98e on / type ext4 (rw,seclabel,relatime,stripe=16,data=ordered)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev type tmpfs (rw,seclabel,nosuid,mode=755)
devpts on /dev/pts type devpts (rw,seclabel,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
shm on /dev/shm type tmpfs (rw,seclabel,nosuid,nodev,noexec,relatime,size=65536k)
mqueue on /dev/mqueue type mqueue (rw,seclabel,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (ro,seclabel,nosuid,nodev,noexec,relatime)
tmpfs on /sys/fs/cgroup type tmpfs (rw,seclabel,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/systemd type cgroup (ro,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
cgroup on /sys/fs/cgroup/cpuset type cgroup (ro,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpuacct,cpu type cgroup (ro,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/memory type cgroup (ro,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (ro,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (ro,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls type cgroup (ro,nosuid,nodev,noexec,relatime,net_cls)
cgroup on /sys/fs/cgroup/blkio type cgroup (ro,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (ro,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (ro,nosuid,nodev,noexec,relatime,hugetlb)
tmpfs on /run/secrets type tmpfs (rw,seclabel,nosuid,nodev,noexec,relatime)
/dev/sda3 on /etc/resolv.conf type xfs (rw,seclabel,relatime,attr2,inode64,noquota)
/dev/sda3 on /etc/hostname type xfs (rw,seclabel,relatime,attr2,inode64,noquota)
/dev/sda3 on /etc/hosts type xfs (rw,seclabel,relatime,attr2,inode64,noquota)
devpts on /dev/console type devpts (rw,seclabel,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
proc on /proc/asound type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/bus type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/fs type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/irq type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/sys type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/sysrq-trigger type proc (ro,nosuid,nodev,noexec,relatime)
tmpfs on /proc/kcore type tmpfs (rw,seclabel,nosuid,mode=755)
tmpfs on /proc/timer_stats type tmpfs (rw,seclabel,nosuid,mode=755)
Busybox镜像虽然小巧,但提供了常见的Linux命令,读者可以使用它快熟熟悉Linux命令。

本文标签

除非注明,文章均为( 老薛 )原创,转载请保留链接: http://www.bdkyr.com/operation/1412.html

随便看看

0