簡體   English   中英

在 Gitlab-ci.yaml 管道中使用 spring-boot:build-image 創建 docker 鏡像

[英]Using spring-boot:build-image in Gitlab-ci.yaml Pipeline to create a docker image

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. 該命令在終端開發工作站上運行良好。 但是 Gitlab 的 CI/CD 管道正在拋出錯誤。 感謝任何人可以提供幫助。

[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

您必須在 Docker服務中使用 Docker 來構建您的圖像並通過services添加它:

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

我遇到了同樣的問題,我終於能夠通過設置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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM