Docker — 从入门到实践
  • 前言
  • 修订记录
  • 如何贡献
  • Docker 简介
    • 什么是 Docker
    • 为什么要用 Docker
  • 基本概念
    • 镜像
    • 容器
    • 仓库
  • 安装 Docker
    • Ubuntu
    • Debian
    • Fedora
    • CentOS
    • Raspberry Pi
    • macOS
    • Windows 10
    • 镜像加速器
    • 开启实验特性
  • 使用镜像
    • 获取镜像
    • 列出镜像
    • 删除本地镜像
    • 利用 commit 理解镜像构成
    • 使用 Dockerfile 定制镜像
    • Dockerfile 指令详解
      • COPY 复制文件
      • ADD 更高级的复制文件
      • CMD 容器启动命令
      • ENTRYPOINT 入口点
      • ENV 设置环境变量
      • ARG 构建参数
      • VOLUME 定义匿名卷
      • EXPOSE 暴露端口
      • WORKDIR 指定工作目录
      • USER 指定当前用户
      • HEALTHCHECK 健康检查
      • ONBUILD 为他人作嫁衣裳
      • 参考文档
    • Dockerfile 多阶段构建
      • 实战多阶段构建 Laravel 镜像
    • 构建多种系统架构支持的 Docker 镜像
    • 其它制作镜像的方式
    • 实现原理
  • 操作容器
    • 启动
    • 守护态运行
    • 终止
    • 进入容器
    • 导出和导入
    • 删除
  • 访问仓库
    • Docker Hub
    • 私有仓库
    • 私有仓库高级配置
    • Nexus 3
  • 数据管理
    • 数据卷
    • 挂载主机目录
  • 使用网络
    • 外部访问容器
    • 容器互联
    • 配置 DNS
  • 高级网络配置
    • 快速配置指南
    • 容器访问控制
    • 端口映射实现
    • 配置 docker0 网桥
    • 自定义网桥
    • 工具和示例
    • 编辑网络配置文件
    • 实例:创建一个点到点连接
  • Docker Buildx
    • BuildKit
    • 使用 buildx 构建镜像
    • 使用 buildx 构建多种系统架构支持的 Docker 镜像
  • Docker Compose
    • 简介
    • 安装与卸载
    • 使用
    • 命令说明
    • Compose 模板文件
    • 实战 Django
    • 实战 Rails
    • 实战 WordPress
  • Swarm mode
    • 基本概念
    • 创建 Swarm 集群
    • 部署服务
    • 使用 compose 文件
    • 管理密钥
    • 管理配置信息
    • 滚动升级
  • 安全
    • 内核命名空间
    • 控制组
    • 服务端防护
    • 内核能力机制
    • 其它安全特性
    • 总结
  • 底层实现
    • 基本架构
    • 命名空间
    • 控制组
    • 联合文件系统
    • 容器格式
    • 网络
  • Etcd 项目
    • 简介
    • 安装
    • 集群
    • 使用 etcdctl
  • CoreOS 项目
    • 简介
    • 工具
  • Kubernetes - 开源容器编排引擎
    • 简介
    • 基本概念
    • 架构设计
  • 部署 Kubernetes
    • 使用 kubeadm 部署 kubernetes
    • 在 Docker Desktop 使用
    • 一步步部署 kubernetes 集群
  • Kubernetes 命令行 kubectl
  • 容器与云计算
    • 简介
    • 腾讯云
    • 阿里云
    • 亚马逊云
    • 小结
  • 实战案例 - 操作系统
    • Busybox
    • Alpine
    • Debian Ubuntu
    • CentOS Fedora
    • 本章小结
  • 实战案例 - CI/CD
    • GitHub Actions
    • Drone
      • 部署 Drone
    • Travis CI
  • 在 IDE 中使用 Docker
    • VS Code
  • Docker 开源项目
    • LinuxKit
  • podman -- 下一代 Linux 容器工具
  • 附录
    • 附录一:常见问题总结
    • 附录二:热门镜像介绍
      • Ubuntu
      • CentOS
      • Nginx
      • PHP
      • Node.js
      • MySQL
      • WordPress
      • MongoDB
      • Redis
    • 附录三:Docker 命令查询
      • 客户端命令 (docker)
      • 服务端命令 (dockerd)
    • 附录四:Dockerfile 最佳实践
    • 附录五:如何调试 Docker
    • 附录六:资源链接
  • 归档
    • Mesos - 优秀的集群资源调度平台
      • Mesos 简介
      • 安装与使用
      • 原理与架构
      • Mesos 配置项解析
      • 日志与监控
      • 常见应用框架
      • 本章小结
    • Docker Machine
      • 安装
      • 使用
    • Docker Swarm
Powered by GitBook
On this page
  • 简介
  • 获取官方镜像
  • 运行 busybox
  • 相关资源

Was this helpful?

  1. 实战案例 - 操作系统

Busybox

Previous实战案例 - 操作系统NextAlpine

Last updated 5 years ago

Was this helpful?

简介

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

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

获取官方镜像

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

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

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

$ docker pull busybox:latest
busybox:latest: The image you are pulling has been verified
e433a6c5b276: Pull complete
e72ac664f4f0: Pull complete
511136ea3c5a: Pull complete
df7546f9f060: Pull complete
Status: Downloaded newer image for busybox:latest

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

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

运行 busybox

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

$ docker run -it busybox
/ # grep
BusyBox v1.22.1 (2014-05-22 23:22:11 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)
none on / type aufs (rw,relatime,si=b455817946f8505c)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev type tmpfs (rw,nosuid,mode=755)
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=65536k)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
sysfs on /sys type sysfs (ro,nosuid,nodev,noexec,relatime)
/dev/disk/by-uuid/b1f2dba7-d91b-4165-a377-bf1a8bed3f61 on /etc/resolv.conf type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/disk/by-uuid/b1f2dba7-d91b-4165-a377-bf1a8bed3f61 on /etc/hostname type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/disk/by-uuid/b1f2dba7-d91b-4165-a377-bf1a8bed3f61 on /etc/hosts type ext4 (rw,relatime,errors=remount-ro,data=ordered)
devpts on /dev/console type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
proc on /proc/sys type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/sysrq-trigger type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/irq type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/bus type proc (ro,nosuid,nodev,noexec,relatime)
tmpfs on /proc/kcore type tmpfs (rw,nosuid,mode=755)

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

相关资源

Busybox 官网:

Busybox 官方仓库:

Busybox 官方镜像:

Busybox 官方仓库:

https://busybox.net/
https://git.busybox.net/busybox/
https://hub.docker.com/_/busybox/
https://github.com/docker-library/busybox
Busybox - Linux 瑞士军刀