我正在使用 GitHub 操作“构建并推送 Docker 镜像”,因为它来自 Docker,并且是经过最高评价的经过验证的操作。
我的YAML文件的相关片段如下
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: user/app:latest
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
正如示例中所示。当工作流程运行时,我总是看到错误
10 [stage-1 2/2] COPY --from=build /workspace/target/*.jar app.jar
#10 DONE 0.9s
#12 exporting to image
#12 exporting layers
#12 exporting layers 4.3s done
#12 exporting manifest sha256:dafb0869387b325491aed0cdc10c2d0206aca28006b300554f48e4c389fc3bf1 done
#12 exporting config sha256:f64316c3b529b43a6cfcc933656c77e556fea8e5600b6d0cce8dc09f775cf107 done
#12 pushing layers
#12 pushing layers 0.8s done
#12 ERROR: server message: insufficient_scope: authorization failed
------
> exporting to image:
------
failed to solve: rpc error: code = Unknown desc = server message: insufficient_scope: authorization failed
Error: The process '/usr/bin/docker' failed with exit code 1
我的标准 spring-boot 应用程序的 Dockerfile 内容如下所示
FROM maven:3.6.3-jdk-11-slim AS build
RUN mkdir -p /workspace
WORKDIR /workspace
COPY pom.xml /workspace
COPY src /workspace/src
RUN mvn -B -f pom.xml clean package -DskipTests
FROM openjdk:11-jdk-slim
COPY --from=build /workspace/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
有什么线索可以解决这个问题吗?
使用不同的 GitHub 操作时,我可以发布到 docker-hub,如下所示
- name: Build and push docker image
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: bloque/sales-lead-management
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
使用 Docker 时需要设置路径上下文
build-push-action
。它应该看起来像这样:
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
push: true
tags: user/app:latest
file
选项完全是可选的,但如果省略,它将在根目录中找到 Dockerfile。
还建议使用元数据操作,它为您的 Docker 映像提供更多相关元数据和标签。
以下是我如何在几个项目中为 Spring Boot 应用程序执行此操作的示例:https://github.com/moja-global/FLINT.Reporting/blob/d7504909f8f101054e503a2993f4f70ca92c2577/.github/workflows/docker.yml# L153
对于我们这些在使用 Docker Hub 时遇到此问题的人来说,@PhilipZ. 的评论似乎就是这样:
对我来说,问题是我必须在命令行上登录 Docker:
docker login --username=<username>
– 菲利普·Z. 评论于2022年5月9日20:12