问题描述
我想用 buildx 构建一个多架构映像。这是我的 GitLab CI 管道。第一步,我构建codebase:latest 图像。此映像的构建过程很困难,但最终仅包含静态文件。我想在构建 $CI_REGISTRY_IMAGE/Nginx:latest 和 $CI_REGISTRY_IMAGE/PHP:latest 图像时使用这些文件。
当我使用简单的 docker build 时,它的工作正常:
# Part of ./.deploy/Nginx/Dockerfile
copY --from=codebase /app/public /app/public
但是,当我使用 buildx 时出现错误。
我该如何解决这个问题?
Dockerfile:5
--------------------
3 | copY app.conf /etc/Nginx/conf.d/default.conf
4 | copY Nginx.conf /etc/Nginx/Nginx.conf
5 | >>> copY --from=codebase /app/public /app/public
6 | workdir /app
7 |
--------------------
error: Failed to solve: rpc error: code = UnkNown desc = Failed to load cache key: pull access denied,repository does not exist or may require authorization: server message: insufficient_scope: authorization Failed
.gitlab-ci.yml
stages:
- buildx
- deploy-images
buildx:
image: docker:19.03-git
stage: buildx
variables:
GIT_STRATEGY: none
DOCKER_TLS_CERTDIR: ''
DOCKER_DRIVER: overlay2
artifacts:
paths:
- buildx
expire_in: 1 hour
services:
- docker:19.03-dind
script:
- export DOCKER_BUILDKIT=1
- git clone git://github.com/docker/buildx ./docker-buildx
- docker build --platform=local -o . ./docker-buildx
deploy-images:
stage: deploy-images
image: docker:19.03.5
services:
- name: docker:19.03.5-dind
command: ["--experimental"]
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
CI_BUILD_ARCHS: "linux/amd64,linux/arm64"
before_script:
- mkdir -p ~/.docker/cli-plugins
- mv buildx ~/.docker/cli-plugins/docker-buildx
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
- docker buildx create --use --name mybuilder
script:
- docker buildx build --platform "$CI_BUILD_ARCHS" -f ./.deploy/codebase/Dockerfile -t codebase:latest .
- docker buildx build --platform "$CI_BUILD_ARCHS" --push -t $CI_REGISTRY_IMAGE/Nginx:latest ./.deploy/Nginx/.
- docker buildx build --platform "$CI_BUILD_ARCHS" --push -t $CI_REGISTRY_IMAGE/PHP:latest ./.deploy/PHP/.
only:
- master
./.deploy/Nginx/Dockerfile
FROM Nginx:alpine
copY app.conf /etc/Nginx/conf.d/default.conf
copY Nginx.conf /etc/Nginx/Nginx.conf
copY --from=codebase /app/public /app/public
workdir /app
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)