Reputation: 91
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]
maven-build:
image: maven:3-jdk-11
stage: build
script:
- "mvn spring-boot:build-image"
artifacts:
paths:
- target/*.jar
Upvotes: 9
Views: 4399
Reputation: 40337
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
Upvotes: 6
Reputation: 5154
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
Upvotes: 2