我需要从容器访问主机中的测试结果文件。我知道我需要创建一个在主机和容器之间映射的卷,如下所示,但是我什么也没写到主机上。

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 run如下所示:
docker run --rm -it -v /codecoveragereports:/app/test/MyApplication.UnitTests/codecoveragereports routethink.tests:latest

我可能做错了什么?

最佳答案

看起来像是权限问题。
-v /codecoveragereports:/app/***/codecoveragereports正在/根目录下安装目录,这很危险,您可能没有权限。

最好在本地安装,例如-v $PWD/codecoveragereports:/app/***/codecoveragereports,其中$PWD是等于当前工作目录的环境变量。

关于docker - 将Docker卷挂载到主机路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53447174/

10-16 16:39