GoogleContainerTools/kaniko
是什么?
gcr.io/kaniko-project/executor:latest
gcr.io/kaniko-project/executor:debug - 包含 shell
参考
专注于在 Kubernetes 构建镜像
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/
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
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/
参考链接:https://wener.me/notes/devops/container/kaniko