在 Gitlab-ci.yaml Pipeline 中使用 spring-boot:build-image 创建 docker 镜像

发布于 2025-01-10 10:42:37 字数 867 浏览 0 评论 0原文

我正在尝试使用命令“spring-boot:build-image”而不使用 Dockerfile 在 Gitlab-ci.yaml (管道)中构建 Spring Boot 应用程序的 docker 映像。该命令在终端开发工作站上运行良好。但是 Gitlab 的 CI/CD Pipeline 抛出了错误。如果有人可以提供帮助,请不胜感激。

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.6.4:build-image (default-cli) on project buildpackdemo: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.6.4:build-image failed: Connection to the Docker daemon at 'localhost' failed with error "[2] No such file or directory"; ensure the Docker daemon is running and accessible: com.sun.jna.LastErrorException: [2] No such file or directory -> [Help 1]

Gitlab-ci.yaml

maven-build:
  image: maven:3-jdk-11
  stage: build
  script:
    - "mvn spring-boot:build-image"
  artifacts:
    paths:
      - target/*.jar

I am trying to build the docker image of a Spring Boot application in Gitlab-ci.yaml (Pipeline) by using the command "spring-boot:build-image" with out using Dockerfile. The command is working fine on terminal development work station. But the CI/CD Pipeline of Gitlab is throwing the error. Appreciate if any one can help.

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.6.4:build-image (default-cli) on project buildpackdemo: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.6.4:build-image failed: Connection to the Docker daemon at 'localhost' failed with error "[2] No such file or directory"; ensure the Docker daemon is running and accessible: com.sun.jna.LastErrorException: [2] No such file or directory -> [Help 1]

Gitlab-ci.yaml

maven-build:
  image: maven:3-jdk-11
  stage: build
  script:
    - "mvn spring-boot:build-image"
  artifacts:
    paths:
      - target/*.jar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别闹i 2025-01-17 10:42:37

我遇到了同样的问题,我终于能够通过设置 DOCKER_HOST 变量来使其正常工作。所以,事情看起来像这样:

variables:
  DOCKER_HOST: tcp://docker:2375

maven-build:
  image: maven:3-jdk-11
  stage: build
  services:
    - docker:dind
  script:
    - "mvn spring-boot:build-image"
  artifacts:
    paths:
      - target/*.jar

I was running into the same issue, and I was finally able to get it working by setting the DOCKER_HOST variable. So, things would look something like this:

variables:
  DOCKER_HOST: tcp://docker:2375

maven-build:
  image: maven:3-jdk-11
  stage: build
  services:
    - docker:dind
  script:
    - "mvn spring-boot:build-image"
  artifacts:
    paths:
      - target/*.jar
硪扪都還晓 2025-01-17 10:42:37

您必须使用 Docker in Docker 服务来构建镜像并添加通过服务

maven-build:
  image: maven:3-jdk-11
  stage: build
  services:
    - docker:dind
  script:
    - "mvn spring-boot:build-image"
  artifacts:
    paths:
      - target/*.jar

You must use the Docker in Docker service to build your image and add it via services:

maven-build:
  image: maven:3-jdk-11
  stage: build
  services:
    - docker:dind
  script:
    - "mvn spring-boot:build-image"
  artifacts:
    paths:
      - target/*.jar
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文