容器镜像构建工具kaniko介绍及基本使用(GoogleContainerTools/kaniko)
2023-09-14 09:01:55 时间
Kaniko
-
GoogleContainerTools/kaniko
是什么?
- 构建容器镜像的工具
- 不依赖 Docker,不需要 root 权限
- 可复现的容器镜像构建
-
gcr.io/kaniko-project/executor:latest
-
gcr.io/kaniko-project/executor:debug - 包含 shell
-
参考
- GitLab runner use Kaniko
-
专注于在 Kubernetes 构建镜像
CAUTION
- 只支持 x86_64
- 不支持 multi-arch 和 manifest
- 不能使用本地 layer 缓存
- 性能可能弱于 dind - GoogleContainerTools/kaniko#875
- registry-mirror 不支持前缀,例如
registry.example.com/dockerhub
# debug 环境
docker run --rm -it -w /workspace --entrypoint sh registry.cn-hongkong.aliyuncs.com/cmi/kaniko-project_executor:debug
mkdir -p /workspace /images /cache
cd /workspace
cat <<DOCKERFILE > Dockerfile
FROM wener/base
RUN apk add coreutils
DOCKERFILE
# --no-push 不推送 --tarPath 生成的 tar 需要设置 --destination
# --context 默认 /workspace
# --cache 启用缓存 --cache-dir 基础镜像缓存目录,默认 /cache --cache-repo 缓存仓库
# --use-new-run 实验特性,提升构建性能
# --reproducible 移除时间戳
/kaniko/executor --context $PWD --dockerfile $PWD/Dockerfile \
--registry-mirror hbcvocvo.mirror.aliyuncs.com \
--no-push --tarPath /images/build.tar --destination=image \
--use-new-run --reproducible
# Docker 认证配置
mkdir -p /kaniko/.docker
# 配置
echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
# 构建并推送
/kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
# 直接构建
# registry.cn-hongkong.aliyuncs.com/cmi/kaniko-project_executor:latest
# gcr.io/kaniko-project/executor:latest
docker run \
-v "$HOME"/.config/gcloud:/root/.config/gcloud \
-v /path/to/context:/workspace \
registry.cn-hongkong.aliyuncs.com/cmi/kaniko-project_executor:latest \
--dockerfile /workspace/Dockerfile \
--destination "$PROJECT_ID/$IMAGE_NAME:$TAG" \
--context dir:///workspace/
dockerhub
cat <<JSON > config.json
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "$(echo -n $USER:$PASSWORD | base64)"
}
}
}
JSON
docker run --rm -it $PWD/config:/kaniko/.docker/config.json --destination=yourimagename
参数
FAQ
性能问题
- https://github.com/GoogleContainerTools/kaniko/issues/875 Kaniko build’s performance much slower comparing with DID solution
拷贝根目录异常阻塞
FROM alpine:3.11 as rootfs
RUN echo 7777
FROM alpine:3.11
# 阻塞
COPY --from=rootfs / /sysroot/
# Workaround https://github.com/GoogleContainerTools/kaniko/issues/960
COPY --from=rootfs /rootfs/ /sysroot/
snapshot 阻塞
参考链接:https://wener.me/notes/devops/container/kaniko
相关文章
- 重新整理 .net core 实践篇—————grpc工具[三十四]
- 自制小工具含源码——博客园图床ImageBed
- 推荐一个以动画效果显示github提交记录的黑科技工具:Gource
- 使用Chrome开发者工具研究JavaScript里函数的原生实现
- 发送请求工具—Advanced REST Client
- 【Android 逆向】逆向修改游戏应用 ( APK 解析工具 | 解包 -> 分析 -> 重打包 -> 签名 流程 )
- InstallShield12豪华版破解版下载|InstallShield下载|软件打包工具
- 【云原生之Docker实战】使用docker部署Notepad个人记事本工具
- C++ Primer 学习笔记_91_用于大型程序的工具 --命名空间
- Git 工具的使用
- 接口文档生成工具Swagger2的使用
- 十年老程序:当破解版Navicat不能再用了,来体验一下这款免费又好用的SQL工具吧
- 详解SBOM:要素、用例和工具
- 监控容器运行时工具Falco