简体   繁体   English

无法使用 docker-compose 将 docker 文件夹安装到主机中

[英]Unable to mount docker folder into host using docker-compose

I'm using a docker container to run cucumber test, after the test finished it will generate a report, I want to copy the report to my host machine.我正在使用 docker 容器运行 cucumber 测试,测试完成后会生成报告,我想将报告复制到我的主机。 Have a report folder at the root of my project and create a test folder in Dockerfile and copy all the files into the container.在我的项目的根目录下有一个报告文件夹,并在 Dockerfile 中创建一个测试文件夹并将所有文件复制到容器中。
Expect: copy reports from container's /test/report folder to host's /report folder期望:将报告从容器的 /test/report 文件夹复制到主机的 /report 文件夹
docker-compose: docker-compose:

version: '3'
services:
  test:
  build:
    context: .
    args:
        xx : "xxx"
  volumes:
  - ./report:/test/report

Dockerfile: Dockerfile:

RUN mkdir /test
WORKDIR /test
COPY . /test
RUN /test/testing.sh

have other configuration in Dockerfile but not related to volume/mount, so didn't post it here.在 Dockerfile 中有其他配置,但与音量/安装无关,所以没有在这里发布。

There should be three reports in the report folder.报告文件夹中应该有三个报告。 Inside the container, the reports can be seen at /test/report after the test, and if the /report in my host not null, it will override the reports in the container.在容器内部,测试后可以在/test/report看到报告,如果我的主机中的/report不是null,它将覆盖容器中的报告。 But the volume doesn't work in reverse order.但是音量不能以相反的顺序工作。 Running this on a windows machine currently.目前在 windows 机器上运行它。

Sounds like you want a bind mount.听起来你想要一个绑定安装。 Also it is normally best to post your whole docker-compose file just so it's easier to debug/reproduce/help.此外,通常最好发布整个 docker-compose 文件,以便更容易调试/复制/帮助。

Try explicitly setting the volume as a bind mount and see how you go:尝试将卷显式设置为绑定挂载,看看你如何 go:

- type: bind
  source: ./report
  target: /test/report

https://docs.docker.com/compose/compose-file/compose-file-v3/#volumes https://docs.docker.com/compose/compose-file/compose-file-v3/#volumes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM