无法将我的二进制文件从 docker 构建的第一阶段复制到第二阶段



我正在使用多阶段构建,但有些东西没有按预期工作。这些图像是自定义的,我们有自己的工件 - 所以不用担心链接,它们正在工作。

我的简单Dockerfile是:

####################      BUILD Stage      ####################
FROM <url>/my-docker-image:latest AS build-image
COPY . /workarea
WORKDIR /workarea
## run the integration tests as well.
RUN INTEGRATION_TESTS=1 make docker
RUN pwd
RUN ls -l cmake-build/linux_64_static_make_Debug/src/
RUN ls -l cmake-build/linux_64_static_make_Debug/tests/
####################      RUN Stage      ####################
FROM <url>/my-test-image:latest AS run-tests-image
WORKDIR /workarea
COPY --from=build-image /workarea/cmake-build/linux_64_static_make_Debug/src/mybinary.tsk /workarea/cmake-build/linux_64_static_make_Debug/src/
COPY --from=build-image /workarea/cmake-build/linux_64_static_make_Debug/tests/unit/mybinary.t.tsk /workarea/cmake-build/linux_64_static_make_Debug/tests/unit/
COPY --from=build-image /opt/bb/etc/entrypoint.d/99-mybinary.sh /opt/bb/etc/entrypoint.d/99-mybinary.sh

第一阶段的期望是使用make docker命令构建 .tsk 文件,该命令是标准 cmake 命令之上的包装器。

我在两者之间添加了 RUN 命令,以查看是否已创建 .tsk 文件。

#12 [build-image 5/7] RUN pwd
#12 sha256:4f0ad0e7daee557776d6c7dfa2faf48dead48ae75ff699a0898879f85255dd30
#12 0.534 /workarea
#12 DONE 0.7s
#13 [build-image 6/7] RUN ls -l cmake-build/linux_64_static_make_Debug/src/
#13 sha256:7989faeb2d337c955e167e5807eb6c6a980e98ab210bbb428b180fc2838686f0
#13 0.617 total 378068
.....
#13 0.617 -rwxr-xr-x 1 root root 290465864 Oct 15 12:04 mybinary.tsk
#13 DONE 0.7s

时间戳是正确的。当COPY运行时,没有什么抱怨。

然后我跑

docke-compose run my-test

并运行相同的ls -l那里什么都没有。因此,即使运行了 COPY 命令,我也看不到文件。

我的"docker-compose.yaml"是:

my-test:
build:
context: .
dockerfile: test.Dockerfile
volumes:
- .:/workarea
environment:
- INTEGRATION_TESTS=1

知道我错过了什么吗?我认为音量有问题。

知道我错过了什么吗?我认为音量有问题。

完全。如果你删除那个bind mount,我的意思是- .:/workarea,你一定会让它工作。

容器的文件夹中已有mybinary.tsk/workarea,但您将主机上的当前工作目录.挂载到容器workarea。然后,主机中的内容将覆盖容器中的内容。

最新更新