我正在尝试使用fabric8docker-maven-plugin
在我的gitlab ci 管道中构建docker 图像。
背景:
我的图像构建阶段gitlab-ci.yml
如下所示:
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
我的 pom 有
<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>
我的 Dockerfile 包含
COPY ./some/directory/ /destination/path/within/image
但是构建失败并出现错误
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" ]
问题:
问题似乎是,在从 构建的容器中,maven$JAVA_IMAGE
正在使用docker:dind
容器的 docker 守护进程 (at tcp://docker-build:2375
) 来构建my-image
(如预期的那样),但docker:dind
容器无权访问$JAVA_IMAGE
容器上的文件./some/directory/
。有没有办法让它访问这些文件,或者将这些文件复制到docker:dind
容器中?还是有更好的方法来做我想做的事情(同时保持服务映像docker:dind
和构建映像之间的分离$JAVA_IMAGE
)?