I am creating a .NET Core 2.0 Web API and I am creating a Docker image. I'm new to Docker, so I apologize if the question was answered.
I have the following Docker file for creating an image. In particular, I run unit tests during the build process, and the results are output to ./test/test_results.xml (in a temporary container created during build, I think). My question is: how do I access these test results after the build is complete?
FROM microsoft/aspnetcore-build:2.0 AS build-env WORKDIR /app # Copy main csproj file for DataService COPY src/DataService.csproj ./src/ RUN dotnet restore ./src/DataService.csproj # Copy test csproj file for DataService COPY test/DataService.Tests.csproj ./test/ RUN dotnet restore ./test/DataService.Tests.csproj # Copy everything else (excluding elements in dockerignore) COPY . ./
One approach I took is a comment on the line # COPY --from=build-env /app/test/test_results.xml . . This puts test_results.xml in my final image. Then I can extract these results and remove test_results.xml from the final image using the following powershell script command.
$id=$(docker create dataservice) docker cp ${id}:app/test_results.xml ./test/test_results.xml docker start $id docker exec $id rm -rf /app/test_results.xml docker commit $id dataservice docker rm -vf $id
This, however, seems ugly, and I wonder if there is a cleaner way to do this.
I was hoping there was a way to set the volume during docker build , but it doesn't seem like it will be supported in the official Docker.
Now I look at creating a separate image, only for unit tests.
Not sure if there is a recommended way to achieve what I want.
source share