4

I am building my spring boot native application on an alpine (openjdk:13-alpine) docker image.

./mvnw spring-boot:build-image -DskipTests

When doing this I got an error :

[INFO] Building image 'docker.io/library/bff-distributor:0.0.1-SNAPSHOT'
[INFO] 
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO]  > Pulling builder image 'docker.io/paketobuildpacks/builder:tiny' 100%
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:54 min
[INFO] Finished at: 2021-04-16T15:26:34Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.4:build-image (default-cli) on project bff-distributor: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.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]

My gitlab.ci configuration

build:
  image: openjdk:13-alpine
  stage: build
  script:
    - chmod 755 ./mvnw
    - ./mvnw spring-boot:build-image -DskipTests

For information : I need it to be running on a docker image as the building it's part of my gitlab ci/cd stage.

Antoine Grenard
  • 1,712
  • 3
  • 21
  • 41
  • Do you have docker installed locally? – Alexander.Furer Apr 16 '21 at 15:53
  • It looks like it's trying to access Docker via a TCP socket; that's a very dangerous configuration and wouldn't usually be enabled. Do you have a `DOCKER_HOST` environment variable set? Can you provide a more complete reproduction recipe? – David Maze Apr 16 '21 at 16:00
  • I just downloaded a spring native application with spring initializer and tried to build it through gitlab ci/cd in my image with this script – Antoine Grenard Apr 16 '21 at 16:13
  • 1
    The `spring-boot:build-image` goal requires access to a Docker daemon. You'll need to configure the build container to have access to Docker, possibly using either the "Docker-in-Docker" or "Docker socket binding" solutions shown here: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html – Scott Frederick Apr 16 '21 at 20:46

1 Answers1

3

As the link provided Scott says, you should use Docker in Docker to do what you want.

So, replace the openjdk image by the docker image (https://hub.docker.com/_/docker) and activate the dind service. As you need Java for the Maven execution, you can simply install jdk in the "before_script" section.

Here is my gitlab-ci script for the same kind of project :

  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_TLS_CERTDIR: ""
  image: docker:20.10.8-dind-alpine3.13
  services:
    - docker:20.10.8-dind
  stage: build_push
  before_script:
    - apk add --update openjdk11
  script:
    - chmod 755 ./mvnw
    - ./mvnw spring-boot:build-image
schaillon
  • 46
  • 2
  • I am struggling with a similar problem when creating a jenkins pipeline script for my spring boot maven project. I am using 'maven:3.8.1-adoptopenjdk-11' as my docker image but it probably doesn't have docker within it. My jenkins server is running as a docker container with another dind docker instance also running. Could you please guide me what should be the right docker image specified in my Jenkinsfile? – Andy Dufresne Nov 29 '21 at 14:13