3

I'm attempting to use fabric8's docker-maven-plugin to build docker images within my gitlab ci pipeline.

Background:

My image build stage in gitlab-ci.yml looks like:

build_image:
  stage: build
  image: $JAVA_IMAGE
  services:
    - name: docker:dind
      alias: docker-build
  script:
    - ./mvnw docker:build
  allow_failure: true
  except: *nobuild
  tags:
    - autoscaler

My pom has

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>0.30.0</version>
    <configuration>
        <!-- the hostname should be the same as the service alias specified in the gitlab ci file-->
        <dockerHost>tcp://docker-build:2375</dockerHost>
        <images>
            <image>
                <name>my-image</name>
                <build>
                    <contextDir>${project.basedir}/path/where/Dockerfile/lives</contextDir>
                    <filter>false</filter>
                    <tags>
                        <tag>latest</tag>
                        <tag>${project.version}</tag>
                    </tags>
                </build>
            </image>
        </images>
    </configuration>
</plugin>

And my Dockerfile contains

COPY ./some/directory/ /destination/path/within/image

But the build fails with the error

41014 [ERROR] DOCKER> Unable to build image [my-image] : "COPY failed: stat /var/lib/docker/tmp/docker-builder785340074/some/directory/: no such file or directory"  ["COPY failed: stat /var/lib/docker/tmp/docker-builder785340074/some/directory/: no such file or directory" ]

Question:

The problem seems to be that maven, within the container built from $JAVA_IMAGE, is using the docker:dind container's docker daemon (at tcp://docker-build:2375) to build my-image (as intended), but the docker:dind container does not have access to the files on the $JAVA_IMAGE container at ./some/directory/. Is there a way to give it access to those files, or to copy those files onto the docker:dind container? Or is there a better way to do what I'm trying to do (while maintaining the separation between the service image docker:dind and the build image $JAVA_IMAGE)?

Mike S
  • 1,451
  • 1
  • 16
  • 34
  • 1
    May be the descriptions found here: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html are helpfull. They describe how to set a mount-point for the dind container. – Kimses Oct 08 '19 at 11:29

0 Answers0