我需要从容器中访问主机上的测试结果文件。我知道需要创建一个卷,将主机和容器映射起来,例如下面这样,但是我没有把任何内容写入主机。
docker run --rm -it -v <host_directory_path>:<container_path> imagename
Dockerfile:
FROM microsoft/dotnet:2.1-sdk AS builder
WORKDIR /app
COPY ./src/MyApplication.Program/MyApplication.Program.csproj ./src/MyApplication.Program/MyApplication.Program.csproj
COPY nuget.config ./
WORKDIR ./src/MyApplication.Program/
RUN dotnet restore
WORKDIR /app
COPY ./src ./src
WORKDIR ./src/MyApplication.Program/
RUN dotnet build MyApplication.Program.csproj -c Release
FROM builder as tester
WORKDIR /app
COPY ./test/MyApplication.UnitTests/MyApplication.UnitTests.csproj ./test/MyApplication.UnitTests/MyApplication.UnitTests.csproj
WORKDIR ./test/MyApplication.UnitTests/
RUN dotnet restore
WORKDIR /app
COPY ./test ./test
WORKDIR ./test/MyApplication.UnitTests/
RUN dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
ENTRYPOINT ["dotnet", "reportgenerator", "-reports:coverage.cobertura.xml", "-targetdir:codecoveragereports", "-reportTypes:htmlInline"]
入口点处的命令正在正确地运行。 它将输出写入MyApplication.UnitTests/codecoveragereports
目录,但不会写入主机目录。
我的docker运行如下:
docker run --rm -it -v /codecoveragereports:/app/test/MyApplication.UnitTests/codecoveragereports routethink.tests:latest
我可能做错了什么?
VOLUME /app/test/MyApplication.UnitTests/codecoveragereports
- johnpatonVOLUME
通常只会导致意外的副作用;它对docker run -v
选项没有影响。 - David Maze/
代表我正在运行docker run
的路径? - Dave New