【发布时间】:2018-04-17 09:02:59
【问题描述】:
在构建 docker-compose 文件的过程中运行 unittests 后,在容器中创建的文件未显示在我的本地文件系统上。
我有以下 Dockerfile:
# IDM.Test/Dockerfile
FROM microsoft/aspnetcore-build:2.0
WORKDIR /src
# Variables
ENV RESTORE_POLICY --no-restore
ENV IGNORE_WARNINGS -nowarn:msb3202,nu1503
# Restore
COPY IDM.sln ./
# Copying and restoring other projects...
COPY IDM.Test/IDM.Test.csproj IDM.Test/
RUN dotnet restore IDM.Test/IDM.Test.csproj $IGNORE_WARNINGS
# Copy
COPY . .
# Test
RUN dotnet test IDM.Test/IDM.Test.csproj -l "trx;LogFileName=test-results.xml"
RUN ls -alR
运行RUN ls -alR 时,我可以看到文件/src/IDM.Test/TestResults/test-results.xml 是在容器内生成的。到目前为止一切顺利。
我正在使用docker-compose -f docker-compose.test.yml build 开始构建。
docker-compose 看起来像这样:
version: '3'
services:
idm.webapi:
image: idmwebapi
build:
context: .
dockerfile: IDM.Test/Dockerfile
volumes:
- ./IDM.Test/TestResults:/IDM.Test/TestResults/
我已经在本地创建了文件夹IDM.Test/TestResults,但是成功运行docker-compose build命令后什么都没有出现。
有什么线索吗?
【问题讨论】:
-
你能不能把
./IDM.Test/TestResults:/IDM.Test/TestResults/改成./IDM.Test/TestResults:/IDM.Test/TestResults(去掉最后一个斜杠) -
试过了,没用
-
你确定目录
/IDM.Test/TestResults在容器的根目录下吗? -
在 dockerfile 中,
/src设置为 workdir,在成功构建后,我得到以下输出:Total tests: 183. Passed: 183. Failed: 0. Skipped: 0. Test Run Successful. Test execution time: 23.1050 Seconds Results File: /src/IDM.Test/TestResults/test-results.xml Removing intermediate container d84ea055f2b6 ---> 10e517b0dfcb Successfully built 10e517b0dfcb Successfully tagged idmwebapi:latest在路径中显示文件:` /src/IDM.Test/TestResults/test-results .xml` -
在这种情况下你必须挂载卷
./IDM.Test/TestResults:/src/IDM.Test/TestResults
标签: docker docker-compose docker-volume