I'm trying to build a docker container in Visual Studio Code (I'm actually working with IoT Edge modules). The application is the OPC Publisher module for IoT Edge that you can find here. I'm working on Windows 10
I have the following Dockerfile:
ARG runtime_base_tag=2.1-runtime-bionic-arm32v7
ARG build_base_tag=2.1-sdk-bionic-arm32v7
FROM microsoft/dotnet:${build_base_tag} AS build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY ./src/*.csproj ./opcpublisher/
WORKDIR /app/opcpublisher
RUN dotnet restore
# copy and publish app
WORKDIR /app
COPY ./src/. ./opcpublisher/
WORKDIR /app/opcpublisher
RUN dotnet publish -c Release -o out
# start it up
FROM microsoft/dotnet:${runtime_base_tag} AS runtime
WORKDIR /app
COPY --from=build /app/opcpublisher/out ./
WORKDIR /appdata
ENTRYPOINT ["dotnet", "/app/opcpublisher.dll"]
When I run the command docker build I have the following error:
Step 7/16 : RUN dotnet restore
---> Running in d6bd61466c67
qemu: Unsupported syscall: 389
And then it's waiting indefinitely, the process is not exiting with error code or something else.
It seems to be an error with the .NET command. I commented the step 7 in the Dockerfile and I got the same error at the step RUN dotnet publish -c Release -o out
I installed qemu and .NET cli tools (this ?) but I still have the error.
Does someone have an idea of the problem ?
Thanks
EDIT
When I run VS code as asdministrator, I have this additional output:
Step 7/16 : RUN dotnet restore
---> Running in 293e6271cb65
qemu: Unsupported syscall: 389
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault
The command '/bin/sh -c dotnet restore' returned a non-zero code: 139
And the command stops (no more indefinitely wait)
Related
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 researched this for the past couple days and none of the research I've found has helped me solve this issue, including restarting Docker, restarting Docker service, restarting Visual Studio, deleting Nuget, adjusting proxy settings, adjusting Nuget.config etc etc.
Ultimately the error message I get is Unable to load the service index for source https://api.nuget.org/v3/index.json. but please bear with me I'm giving exect steps to reproduce this error.
When I create an ASP.NET Core Web Application in Visual Studio 2019, then Add Docker support to the project (Right click project, choose Add -> Docker Support...), a Dockerfile is created which looks like this:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
WORKDIR /src
COPY ["WebApplication3/WebApplication3.csproj", "WebApplication3/"]
RUN dotnet restore "WebApplication3/WebApplication3.csproj"
COPY . .
WORKDIR "/src/WebApplication3"
RUN dotnet build "WebApplication3.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication3.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication3.dll"]
When I build the docker image (Right click dockerfile, choose Build Docker Image), it builds fine and I get:
Starting up container(s)...
docker build -f "C:\Users\TheUser\source\repos\WebApplication3\WebApplication3\Dockerfile" --force-rm -t webapplication3:dev --target base --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=WebApplication3" "C:\Users\TheUser\source\repos\WebApplication3"
Sending build context to Docker daemon 4.396MB
Step 1/6 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
---> dc28376d4369
Step 2/6 : WORKDIR /app
---> Using cache
---> d0cbefb504d1
Step 3/6 : EXPOSE 80
---> Using cache
---> 865f960359d6
Step 4/6 : EXPOSE 443
---> Using cache
---> 4d040d5c8a4c
Step 5/6 : LABEL com.microsoft.created-by=visual-studio
---> Using cache
---> 4223be37abec
Step 6/6 : LABEL com.microsoft.visual-studio.project-name=WebApplication3
---> Running in d1ced38ba0fa
Removing intermediate container d1ced38ba0fa
---> fb400230edf4
Successfully built fb400230edf4
Successfully tagged webapplication3:dev
docker run -dt -v "C:\Users\TheUser\onecoremsvsmon\16.4.0067.0:C:\remote_debugger:ro" -v "C:\Users\TheUser\source\repos\WebApplication3\WebApplication3:C:\app" -v "C:\Users\TheUser\source\repos\WebApplication3:C:\src" -v "C:\Users\TheUser\AppData\Roaming\Microsoft\UserSecrets:C:\Users\ContainerUser\AppData\Roaming\Microsoft\UserSecrets:ro" -v "C:\Users\TheUser\AppData\Roaming\ASP.NET\Https:C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Https:ro" -v "C:\Users\TheUser\.nuget\packages\:c:\.nuget\fallbackpackages2" -v "C:\Program Files\dotnet\sdk\NuGetFallbackFolder:c:\.nuget\fallbackpackages" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "ASPNETCORE_ENVIRONMENT=Development" -e "ASPNETCORE_URLS=https://+:443;http://+:80" -e "NUGET_PACKAGES=c:\.nuget\fallbackpackages2" -e "NUGET_FALLBACK_PACKAGES=c:\.nuget\fallbackpackages;c:\.nuget\fallbackpackages2" -P --name WebApplication3 --entrypoint C:\remote_debugger\x64\msvsmon.exe webapplication3:dev /noauth /anyuser /silent /nostatus /noclrwarn /nosecuritywarn /nofirewallwarn /nowowwarn /fallbackloadremotemanagedpdbs /timeout:2147483646 /LogDebuggeeOutputToStdOut
eba5dec02ed7a80158340d6f8d6af504b86edf7cd6944eb1d4ce71f7847fabb5
Container started successfully.
========== Finished ==========
However if I add a .Net Core Class Library to the solution, add that class library as a project reference to the Web Application and Add Docker Support again, I get a new Dockerfile that looks like this:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
WORKDIR /src
COPY ["WebApplication3/WebApplication3.csproj", "WebApplication3/"]
COPY ["ClassLibrary1/ClassLibrary1.csproj", "ClassLibrary1/"]
RUN dotnet restore "WebApplication3/WebApplication3.csproj"
COPY . .
WORKDIR "/src/WebApplication3"
RUN dotnet build "WebApplication3.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication3.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication3.dll"]
And when I Build Docker Image again this time I get an error which looks like this:
1>------ Rebuild All started: Project: ClassLibrary1, Configuration: Debug Any CPU ------
1>ClassLibrary1 -> C:\Users\TheUser\source\repos\WebApplication3\ClassLibrary1\bin\Debug\netcoreapp3.1\ClassLibrary1.dll
2>------ Rebuild All started: Project: WebApplication3, Configuration: Debug Any CPU ------
2>docker rm -f eba5dec02ed7a80158340d6f8d6af504b86edf7cd6944eb1d4ce71f7847fabb5
2>eba5dec02ed7a80158340d6f8d6af504b86edf7cd6944eb1d4ce71f7847fabb5
2>WebApplication3 -> C:\Users\TheUser\source\repos\WebApplication3\WebApplication3\bin\Debug\netcoreapp3.1\WebApplication3.dll
2>WebApplication3 -> C:\Users\TheUser\source\repos\WebApplication3\WebApplication3\bin\Debug\netcoreapp3.1\WebApplication3.Views.dll
2>Docker version 19.03.8, build afacb8b
2>docker build -f "c:\users\TheUser\source\repos\webapplication3\webapplication3\dockerfile" --force-rm -t webapplication3 --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=WebApplication3" "c:\users\TheUser\source\repos\webapplication3"
2>Sending build context to Docker daemon 4.4MB
2>
2>Step 1/20 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
2> ---> dc28376d4369
2>Step 2/20 : WORKDIR /app
2> ---> Using cache
2> ---> d0cbefb504d1
2>Step 3/20 : EXPOSE 80
2> ---> Using cache
2>Step 4/20 : EXPOSE 443
2> ---> 865f960359d6
2> ---> Using cache
2> ---> 4d040d5c8a4c
2>Step 5/20 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
2> ---> c67fa4d2a089
2>Step 6/20 : WORKDIR /src
2> ---> Using cache
2> ---> 14763e98238e
2>Step 7/20 : COPY ["WebApplication3/WebApplication3.csproj", "WebApplication3/"]
2> ---> ad0ded95d169
2>Step 8/20 : COPY ["ClassLibrary1/ClassLibrary1.csproj", "ClassLibrary1/"]
2> ---> 22667eda405c
2>Step 9/20 : RUN dotnet restore "WebApplication3/WebApplication3.csproj"
2> ---> Running in a3e6a184b4e9
2> Restore completed in 495.4 ms for C:\src\ClassLibrary1\ClassLibrary1.csproj.
2>C:\Program Files\dotnet\sdk\3.1.201\NuGet.targets(124,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\src\WebApplication3\WebApplication3.csproj]
2>C:\Program Files\dotnet\sdk\3.1.201\NuGet.targets(124,5): error : No such host is known. [C:\src\WebApplication3\WebApplication3.csproj]
2>Removing intermediate container a3e6a184b4e9
2>The command 'cmd /S /C dotnet restore "WebApplication3/WebApplication3.csproj"' returned a non-zero code: 1
2>c:\users\TheUser\source\repos\webapplication3\webapplication3\dockerfile : error CTC1014: Docker command failed with exit code 1.
2>c:\users\TheUser\source\repos\webapplication3\webapplication3\dockerfile : error CTC1014: The command 'cmd /S /C dotnet restore "WebApplication3/WebApplication3.csproj"' returned a non-zero code: 1
2>Done building project "WebApplication3.csproj" -- FAILED.
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
Should be easy to reproduce. Why does it work without the class library reference then error when adding a reference? Do I need to update the Dockerfile with something extra? I have been going around in circles with this and none of the other posts on the subject have phrased it this way or given me any answers that work for me.
The actual error seems to be:
Unable to load the service index for source https://api.nuget.org/v3/index.json
Which means that nuget is failing to access the endpoint when it is trying to download the dependencies.
There are a number of solutions to this listed here
https://github.com/NuGet/Home/issues/2880
and also
Nuget connection attempt failed "Unable to load the service index for source"
Not able to reproduce it. This is my docker file.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["WebApplication1.csproj", ""]
COPY ["../ClassLibrary1/ClassLibrary1.csproj", "../ClassLibrary1/"]
RUN dotnet restore "./WebApplication1.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
Different line:
COPY ["../ClassLibrary1/ClassLibrary1.csproj", "../ClassLibrary1/"]
RUN dotnet restore "./WebApplication1.csproj"
I think your csproj and sln file are in different folder. When using visual studio make sure you select the option: Place solution and project file in the same folder
2nd Update to the answer:
With every project that you add/reference. Please add support for Docker.
This'll update the docker file.
Are you behind a proxy of some sort? Corporate or otherwise.
I was able to get around this issue by setting the http_proxy in my Dockerfile.
ARG HTTP_PROXY="http://username:password#proxy.example.com:8080"
Full Dockerfile example below:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
ARG HTTP_PROXY="http://username:password#proxy.example.com:8080"
USER administrator
RUN dotnet restore
# Copy everything else and build
COPY . ./
USER administrator
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "myapp.dll"]
If you can't access that nuget endpoint then I'd be curious about 2 things:
Maybe you don't mean to be at all
All of your dependencies live in a private repository (a different endpoint)
If both or either of 1 and 2 above are true and you have a NuGet.Config file managing your dependencies then try and remove any hard-coded Package References from your *.csproj file, then try your docker build again.
If you don't have a NuGet.Config and are referencing your project packages directly from your *.csproj file still I would recommend creating one and removing those references from the project file itself. If not for Docker purposes, then at least for the sake of good organization/separation of concerns.
One last thing, make sure that NuGet.Config file is at the same directory level as your Dockerfile. Dockerfiles will not "see anything" not at their same directory level (even if you have proper relative paths in your Dockerfile so it could theoretically see them if it worked that way).
I ran into a similar problem with dotnet restore causing the Unable to load the service index for source https://api.nuget.org/v3/index.json.
For me the solution was to set dns in the Docker Engine settings, as described in one of the answers in here: Docker container cannot resolve hosts
I added docker support(Windows) in visual studio to an asp.net core project. It runs fine in debug mode. But shows the error as below when in "Release" mode. I've tried switching to a different network (Hotspot over 4G) but still shows the same error message.
Below is the generated docker file.
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809 AS build
WORKDIR /src
COPY ["BlankSite/BlankSite.csproj", "BlankSite/"]
RUN dotnet restore "BlankSite/BlankSite.csproj"
COPY . .
WORKDIR "/src/BlankSite"
RUN dotnet build "BlankSite.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "BlankSite.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "BlankSite.dll"]
Error Message:
>Step 7/18 : RUN dotnet restore "BlankSite/BlankSite.csproj"
1> ---> a406dac3ca1d
1> ---> Running in 38089ed5e181
1>C:\Program Files\dotnet\sdk\2.2.300\NuGet.targets(121,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\src\BlankSite\BlankSite.csproj]
1>C:\Program Files\dotnet\sdk\2.2.300\NuGet.targets(121,5): error : No such host is known [C:\src\BlankSite\BlankSite.csproj]
1>The command 'cmd /S /C dotnet restore "BlankSite/BlankSite.csproj"' returned a non-zero code: 1
1>C:\Users\vincentliao\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.7.9\build\Container.targets(196,5): error CTP1001: An error occurred while attempting to build Docker image.
Your container does not have internet access. To fixe that, follow this. In the case that you don't need the internet access, you can set a private repository instead of nuget.org.
I am attempting to build a .Net Core 3.0 (preview) project in a DevOps build pipeline.
The steps in my azure-pipelines.yml executes up to the "docker build" step, successfully initiating the build process.
The Docker file is read and executed up to the "dotnet build" step after which the following error is thrown.
error MSB3024: Could not copy the file "/src/obj/Release/netcoreapp3.0/" to the destination file "/app/", because the destination is a folder instead of a file. To copy the source file into a folder, consider using the DestinationFolder parameter instead of DestinationFiles. [/src/.csproj]
I have attempted to build locally by executing dotnet build ".csproj" -c Release -o /app
The build then succeeds with 0 errors and 0 warnings. Could this be related to an SDK issue in DevOps?
Any advice would be greatly appreciated.
The build command from my Docker file.
RUN dotnet build "<project>.csproj" -c Release -o /app
--- {OMITED}
---1ff83de4bdba
Step 5/16 : WORKDIR /src
---Running in 972629766fad
Removing intermediate container 972629766fad
---1325ecd8e7c3
Step 6/16 : COPY ["<projectname>.csproj", "<projectname>/"]
---a4ba463683dc
Step 7/16 : RUN dotnet restore "<projectname>/<projectname>.csproj"
---Running in 82bb9095d412
Restore completed in 14.08 sec for /src/<projectname>/<projectname>.csproj.
Removing intermediate container 82bb9095d412
---7b0cc236782e
Step 8/16 : COPY . .
---884bb695bfb3
Step 9/16 : WORKDIR /src
---Running in 817b001e2060
Removing intermediate container 817b001e2060
---40b8690ecb63
Step 10/16 : RUN dotnet build "<projectname>.csproj" -c Release -o /app
---Running in 48d79b81c3cb
Microsoft (R) Build Engine version 16.0.462+g62fb89029d for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 531.02 ms for /src/<projectname>.csproj.
/usr/share/dotnet/sdk/3.0.100-preview5-011568/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(157,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview [/src/<projectname>.csproj]
/usr/share/dotnet/sdk/3.0.100-preview5-011568/Microsoft.Common.CurrentVersion.targets(4560,5): error MSB3024: Could not copy the file "/src/obj/Release/netcoreapp3.0/<projectname>" to the destination file "/app/<projectname>", because the destination is a folder instead of a file. To copy the source file into a folder, consider using the DestinationFolder parameter instead of DestinationFiles. [/src/<projectname>.csproj]
Build FAILED.
/usr/share/dotnet/sdk/3.0.100-preview5-011568/Microsoft.Common.CurrentVersion.targets(4560,5): **error MSB3024: Could not copy the file "/src/obj/Release/netcoreapp3.0/<projectname>" to the destination file "/app/<projectname>", because the destination is a folder instead of a file. To copy the source file into a folder, consider using the DestinationFolder parameter instead of DestinationFiles. **[/src/<projectname>.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:11.43
The command '/bin/sh -c dotnet build "<projectname>.csproj" -c Release -o /app' returned a non-zero code: 1
##[error]Bash exited with code '1'.
##[section]Finishing: docker build
In my case the Assembly name of my project was the same as the name of the project and also the same as the directory name of that project. Once I changed the assembly name in the project properties to something else, this error was gone.
in my case i had to rename the project folder to be different than the project itself in dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
WORKDIR /src
COPY ["<project-name>.csproj", "<project-name>_build/"]
RUN dotnet restore "<project-name>_build/<project-name>.csproj"
I am assuming this is an issue with the .Net Core 3.0 preview5 SDK. I have created the project in .Net Core 2.2 and it build successfully.
When adding the following parameters on the dotnet build command, the build succeeds in .Net Core 3.0
RUN dotnet build ".csproj" -c Release -r linux-musl-x64 -o /app --no-restore
The DockerFile below built successfully in DevOps
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
WORKDIR /src
COPY ["<project-name>.csproj", "<project-name>/"]
RUN dotnet restore "<project-name>/<project-name>.csproj" -r linux-musl-x64
COPY . "<project-name>/"
WORKDIR "/src/<project-name>"
RUN dotnet build "<project-name>.csproj" -c Release -r linux-musl-x64 -o /app --no-restore
FROM build AS publish
RUN dotnet publish "<project-name>.csproj" -c Release -r linux-musl-x64 -o /app --no-restore
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "<project-name>.dll"]
Running Docker on a Win10 machine. Linux containers enabled. My app runs fine on Windows and Debian images but when I switched to Alpine I get this error
PS C:\Code\TestApp> docker run -it testapp:latest
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/app/TestApp\": stat /app/TestApp: no such file or directory": unknown.
I've tried changing the Entrypoint to match some examples but no dice.
FROM microsoft/dotnet:2.1-runtime-deps-alpine3.7 AS base
WORKDIR /app
FROM microsoft/dotnet:2.1-sdk-alpine3.7 AS build
WORKDIR /src
COPY TestApp/TestApp.csproj TestApp/
RUN dotnet restore TestApp/TestApp.csproj
COPY . .
WORKDIR /src/TestApp
RUN dotnet build TestApp.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish TestApp.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
# This is for Windows and Debian images
# ENTRYPOINT ["dotnet", "TestApp.dll"]
ENTRYPOINT ["/app/TestApp"]
Add some debug information in your different stages of this multi-stage build:
RUN ls -alrth /app
(after each COPY or RUN dotnet commands)
And make sure to build it with a name and tag different from your first builds for Windows, in order to be sure to not try a Windows-built image in your Linux environment.
docker build -t testApp-linux ...