Show HN: 构建更好的基础镜像
该项目旨在构建更优化的基础镜像,主要通过使用 `debootstrap` 自动化创建最小的 Debian 根文件系统。它提供脚本和工具,支持自定义包和配置,并集成安全扫描。项目解决了标准 Dockerfile 构建中存储膨胀、网络效率低下和迭代缓慢的问题。通过该工具,可以构建最小基础镜像,并创建专用变体,如 Java 和 Kafka。项目包含构建脚本、安装脚本和维护脚本,最终生成 `.tar` 格式的镜像。
avkcode / **container-tools ** Public
构建更好的基础镜像
License
MIT license 30 stars 1 fork Branches Tags Activity
avkcode/container-tools
main BranchesTags Go to file Code
Folders and files
Name| Name| Last commit message| Last commit date
---|---|---|---
Latest commit
History
24 Commits
debian| debian
recipes| recipes
scripts| scripts
.gitignore| .gitignore
Dockerfile| Dockerfile
LICENSE| LICENSE
Makefile| Makefile
README.md| README.md
Vagrantfile| Vagrantfile
favicon.svg| favicon.svg
tools.mk| tools.mk
View all files
Repository files navigation
Container Tools
| Container Tools 是一个项目,它提供脚本和实用程序,以使用 debootstrap 自动化创建最小的基于 Debian 的根文件系统 (rootfs)。它支持使用特定包、配置进行自定义,并集成容器化环境的安全扫描。可以很容易地扩展到其他发行版和项目。
---|---
Rational
当使用标准 Dockerfile 构建容器化环境时,每个自定义层都会创建:
- 存储膨胀 - 每个
RUN apt-get install
都会创建一个新层,从而浪费磁盘空间来存储重复的依赖项。 - 网络效率低下 - 在不同的镜像之间发生冗余的包下载。
- 迭代缓慢 - 重建镜像需要重复所有先前的步骤。
使用此工具可以构建:
- 使用 debootstrap 从头开始构建最小的基础镜像。
- 精确地仅在初始构建中包含所需的组件。
- 从通用基础创建专用变体(Java、Kafka 等)。
How it works:
Usage: make <target>
============================
** Debian Linux targets **
============================
|all|
|debian11|
|debian11-java|
|debian11-java-slim|
|debian11-corretto|
|debian11-graal|
|debian11-graal-slim|
|debian11-java-slim-maven|
|debian11-java-slim-gradle|
|debian11-graal-slim-maven|
|debian11-graal-slim-gradle|
|debian11-java-kafka|
|debian11-java-slim-kafka|
In the end it will produce the image
[Image was built successfully]
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Artifact location: debian/dist/debian11-graal-slim/debian11-graal-slim.tar
Artifact size: 124M
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Image was built successfully!
Artifact location: debian/dist/debian11-graal-slim/debian11-graal-slim.tar
To load and run this Docker image, follow these steps:
Load the Docker image from the .tar file:
cat debian/dist/debian11-graal-slim/debian11-graal-slim.tar | docker import - debian/dist/debian11-graal-slim/debian11-graal-slim
Verify the image was loaded successfully:
docker images
Run the Docker container:
docker run -it <IMAGE_NAME>
Replace <IMAGE_NAME> with the name of the image loaded in the first step.
Example:
docker run -it debian/dist/debian11-graal-slim/debian11-graal-slim /bin/bash
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Time elapsed: 193
How to extend
- Add recipe to recipes/
- Make sure that the link to artifact and SHA256 is correct (e.g
sha256sum kafka_2.13-4.0.0.tgz
):
KAFKA_VERSION='4.0.0'
KAFKA_SHA='7b852e938bc09de10cd96eca3755258c7d25fb89dbdd76305717607e1835e2aa'
KAFKA_URL="https://downloads.apache.org/kafka/${KAFKA_VERSION}/kafka_2.13-${KAFKA_VERSION}.tgz"
- Add target to the Makefile
debian11-java-slim-kafka:
$(PRINT_HEADER)
$(DEBIAN_BUILD_SCRIPT) \
--name=$@ \
--keyring=$(DEBIAN_KEYRING) \
--variant=container \
--release=stable \
--recipes=$(JAVA_RECIPES)/java_slim.sh,$(RECIPES)/kafka/kafka.sh \
--scripts=$(SCRIPTS)/security-scan.sh
Profit
Repository Directory Structure
Root Directory
Dockerfile
- Docker 配置用于构建环境Makefile
- 使用不同镜像的目标构建自动化README.md
- 项目文档和使用说明tools.mk
- Makefile 工具和实用程序Vagrantfile
- Vagrant 配置用于开发环境
debian/
debian/debootstrap/
buster
- Debian 10 (Buster) 配置bullseye
- Debian 11 (Bullseye) 配置jessie
- Debian 8 (Jessie) 配置stretch
- Debian 9 (Stretch) 配置unstable
- Debian Unstable 配置wheezy
- Debian 7 (Wheezy) 配置
debian/keys/
buster.gpg
- 用于 Debian Buster 的密钥unstable.gpg
- 用于 Debian Unstable 的密钥
Key Files:
mkimage.sh
- 用于构建 Debian 根文件系统的主脚本
recipes/
recipes/java/
java.sh
- 完整的 JDK 安装java_slim.sh
- 简化的 JDK 安装graalvm.sh
- GraalVM 安装graalvm_slim.sh
- 简化的 GraalVM 安装corretto.sh
- Amazon Corretto JDKmaven.sh
- Apache Mavengradle.sh
- Gradle 构建工具
recipes/kafka/
kafka.sh
- Apache Kafka 安装(在我们的解决方案中添加)
scripts/
security-scan.sh
- 运行 Trivy 安全扫描程序
dist/
- 包含
.tar
格式的最终构建镜像 - 按镜像名称组织(例如,
debian11-java-slim/
)
download/
- 存储下载的包和二进制文件
About
Build better base images
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published