I'm having trouble getting coverlet to run in my docker container. My problems seems similar to this issue, although the problem persists, and there are some differences.
Setup
.NET 6 tests project.
References have Microsoft.NET.Test.Sdk v17.2.0 (latest), and coverlet.collector v3.1.2 (latest)
I'm running the tests in a Dockerfile, like so:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
COPY ["src/MyAPI/", "src/MyAPI/"]
COPY ["tests/MyAPI.Handlers.Tests/", "tests/MyAPI.Handlers.Tests/"]
WORKDIR "/tests/MyAPI.Handlers.Tests"
RUN dotnet restore "MyAPI.Handlers.Tests.csproj" --configfile NuGet.config
FROM build AS publish
WORKDIR /tests/MyAPI.Handlers.Tests
RUN dotnet publish "MyAPI.Handlers.Tests.csproj" -c Release -o /tests/publish --no-restore
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS final
WORKDIR /tests
COPY --from=publish /tests/publish .
ENTRYPOINT ["dotnet", "test", "MyAPI.Handlers.Tests.dll", "--collect:\"XPlat Code Coverage\""]
So i am doing a dotnet publish, and running the tests from there. That should mean that everything is there, that needs to run the tests / coverage.
When i run, i get this error:
Data collection : Unable to find a datacollector with friendly name '"XPlat Code Coverage"'.
What i've confirmed:
Command works outside docker fine (e.g if i do a dotnet publish, then dotnet test with coverage)
I've listed the files in the directory in the container, and confirmed the coverlet DLL's are there
Any suggestions would be great! Thanks in advance :)
I tried by removing \" from argument and it worked.
ENTRYPOINT ["dotnet", "test", "MyAPI.Handlers.Tests.dll", "--collect:XPlat Code Coverage"]
Related
I have a .net solution which has 2 projects, and each project is a microservice (a server). I have a dockerfile which first installs all the dependencies which are used by both projects. Then I publish the solution:
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.sln .
COPY Server/*.csproj ./Server/
COPY JobRunner/*.csproj ./JobRunner/
RUN dotnet restore ./MySolution.sln
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "Server.dll"]
When the solution is published, 2 executables are available: Server.dll and JobRunner.dll. However, I can only start only one of them in Dockerfile.
This seems to be wasteful because restoring the solution is a common step for both Server and JobRunner project. In addition this line RUN dotnet publish -c Release -o out produces both an executable for Server and JobRunner. I could write a separate Dockerfile for each project but this seems redundant as 99% of the build steps for each project is identical.
Is there a way to somehow start 2 executables from a single file without using a script (I don't want that both services will be started in a single container)? The closest I've found is the --target option in docker build but it probably won't work because I'd need multiple entrypoints.
In your Dockerfile, change ENTRYPOINT to CMD in the very last line.
Once you do this, you can override the command by just providing an alternate command after the image name in the docker run command:
docker run ... my-image \
dotnet JobRunner.dll
(In principle you can do this without changing the Dockerfile, but the docker run construction is awkward, and there's no particular benefit to using ENTRYPOINT here. If you're using Docker Compose, you can override either entrypoint: or command: on a container-by-container basis.)
I created an out the box template c# edge solution in VScode using the IoT tools but get the following error when trying to build and push the solution:
Step 4/12 : RUN dotnet restore
---> Running in 22c6f8ceb80c
A fatal error occurred, the folder [/usr/share/dotnet/host/fxr] does not contain any version-numbered child folders
The command '/bin/sh -c dotnet restore' returned a non-zero code: 131
This is clearly happening when its trying to run through the commands in Dockerfile.arm32v7 which has the following in it:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster-arm32v7 AS build-env
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim-arm32v7
WORKDIR /app
COPY --from=build-env /app/out ./
RUN useradd -ms /bin/bash moduleuser
USER moduleuser
ENTRYPOINT ["dotnet", "SampleModule.dll"]
This only happens when building for arm32v7 but works for amd64. I'm building for use on raspberry pi so I need arm32.
Seems to me maybe a problem with my environment but not sure where to look?
I've also seen some comments that you need to build on an ARM host machine if you want it to work but I haven't seen that in the documentation before and doesn't make sense from an ease of development point of view
When submitting a build using az acr build, you can pass in the parameter --platform linux/arm/v7 which should give you an ARM build environment.
If you prefer to build locally, you can try using the pulling the qemu package into the build context in the first stage of your Dockerfile.
I have an Asp.Net core docker image. The last time I tried building it was 2 months ago. Now, I'm getting an error while trying to build it.
Any ideas? Did something break the Microsoft docker image? This is also breaking when trying to publish and run on an Elasticbeanstalk instance.
Complete Error Log:
/usr/share/dotnet/sdk/3.1.201/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1064: Package DnsClient, version 1.2.0 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/app/BacktraderDataApi.csproj]
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
Dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 5000
ENTRYPOINT ["dotnet", "myApp.dll"]
When solutions like using --no-cache are not restoring at all work, it usually indicates that artifact from the host machine are getting copied into the build container. This can cause problems when the host machine and build container have different RIDs. This can commonly occur on Windows machines when running linux containers. The .NET Core Docker Samples suggest using a .dockerignore file to avoid coping the bin and obj directories with your Dockerfiles.
For me it helped adding a --no-cache flag
RUN dotnet publish -c Release -o out --no-cache
Based on the information posted at https://github.com/microsoft/containerregistry/issues/20 for this same issue as well as the information here I tried the following:
dotnet new web
Edit the csproj and added the following:
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
Created the following Dockerfile
# https://hub.docker.com/_/microsoft-dotnet-core
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /source
# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore
# copy and publish app and libraries
COPY . .
RUN dotnet publish -c release -o /app --no-restore
# final stage/image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build /app ./
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
Created the following .dockerignore
# directories
**/bin/
**/obj/
**/out/
# files
Dockerfile*
**/*.trx
**/*.md
**/*.ps1
**/*.cmd
**/*.sh
docker build --pull -t test .
The Dockerfile built without issue. Can you try these steps and report back the results?
I had a very similar problem
error MSB4018: NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder '/usr/local/share/dotnet/sdk/NuGetFallbackFolder'.
I added RUN mkdir -p /usr/local/share/dotnet/sdk/NuGetFallbackFolder.
Then it got a lot farther but failed with a library resolution for something that I believe is just distributed with the SDK.
/usr/share/dotnet/sdk/3.1.201/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1064: Package Microsoft.EntityFrameworkCore.Analyzers, version 3.1.1 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.
I think the mcr.microsoft.com/dotnet/core/sdk:3.1 4/09/2010 Docker image with tags 3.1.201-buster, 3.1-buster, 3.1.201, 3.1, latest is broken.
I changed to the image based on Ubuntu bionic and it just worked again.
USE mcr.microsoft.com/dotnet/core/sdk:3.1-bionic
I was having the same issue, after i read this link https://github.com/dotnet/sdk/issues/3059
I just appended the /restore to build command and it worked.
just like this
RUN dotnet publish --no-restore -c Release -o /app --no-cache /restore
and now it is working just fine.
I've created a simple .NET Core 3.0 web API. In the project directory, I have a Dockerfile that looks like this:
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build-env
WORKDIR /app
# copy over csproj and restore nuget packages
COPY DockerWebApiSandbox.csproj ./
RUN dotnet restore
# copy everything else over into the same directory as the last copy step
# and run the publish step to build and gather output
COPY . ./
RUN dotnet publish -c Release -o output
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "DockerWebApiSandbox.dll"]
When running docker build -t dockerwebapisandbox . from the working directory of my project, I see a failure on step 9 of 10 (third COPY command):
COPY failed: stat
/var/lib/docker/overlay2/f6f3391827aef74f1dab5716635a9119ae250ae94a216bbc0bc7b47c4030d60a/merged/app/out:
no such file or directory
When searching what the community was saying about this error, I found a suggestion here. The suggestion mentions screening into the VM, but this command fails, given that the com.docker.driver.amd64-linux/ directory does not exist where it's being expected. The screen command suggested looks like this: $ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
Other than trying the suggestion from the link above, I've tried uninstalling Docker and Docker Desktop altogether, in addition to the "Factory Reset" option provided in Docker Desktop.
FWIW, I am running MacOS Mojave. TIA for anyone who has suggestions.
I have faced the same error in Node. I was resolve using
COPY . .
Following the instructions on Docker's page I created a very simple Dockerfile that looks like this:
FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "dockertest.dll"]
This is literally a copy of the sample on Docker's site just changed the application name.
I used Visual Studio for Mac to create a very simple ASP.Net application (actually, just the default app with a tiny HTML file added in).
When I first ran docker build -t dockertest . the line with dotnet publish failed. I then ran the dotnet publish manually and got past that.
It now fails on the copy:
Step 9/10 : COPY --from=build-env /app/out .
COPY failed: stat /var/lib/docker/overlay2/1484306cebf1def83638270757e70a8cf874fb5a167f39e5bfaae92a47cc071c/merged/app/out: no such file or directory
What's going on?
So did you run dotnet publish inside the container or on the host machine? The Docker file is trying to run those commands inside the container, so running those on the host will not fix the issue.
Have you tried to right click your project and "Add Docker Support" to your app in VS for Mac? It should generate a docker file and then you can run/debug your app inside the container from within VS.