I am trying to start my .net core web api on container tech. using docker.
Environments=Windows 10,Visual Studio
Docker version:
Client:
Version: 17.12.0-ce
API version: 1.35
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:05:22 2017
OS/Arch: windows/amd64
Server:
Engine:
Version: 17.12.0-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:12:29 2017
OS/Arch: linux/amd64
Experimental: true
My Nuget.Config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json"
protocolVersion="3" />
<add key="Private"
value="http://My_Private_Nuget_Server" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
<packageManagement>
<add key="format" value="0" />
<add key="disabled" value="True" />
</packageManagement>
<apikeys>
<add key="https://www.nuget.org" value="Some_Long_Value" />
</apikeys>
<disabledPackageSources />
</configuration>
My Dockerfile:
FROM microsoft/aspnetcore-build:2.0 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/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "MailAlertWebApiWithEF.dll"]
I' am using Linux Container on windows 10 machine. I have .net core project on Visual Studio 17. When ı add docker support and run from VS 17 everything works fine. API stands up inside a container.But don't work when i close the VS. However When ı try to customize my dockerfile to make my image and container independent from VS. It gives error because of a private .dll
.
In my project ı have a .dll
from my private nuget server. When ı tried without my private .dll
ı can create image. But ı need that .dll
. Docker give me this error:
MailAlertWebApiWithEF.csproj : error NU1101: Unable to find package WebApi.Utils. No packages exist with this id in source(s): nuget.org
I searched this error. The source of problem seems like Nuget.Config file. But it seems good to me because i can see me private nuget server in there. When ı searched the solutions arrows always on linux machines but ı use windows.
1-)So if i can start my project with VS 17 , then my nuget.config file is in correct form. It can see my private nuget server. Right? Then why not docker don't see it?
Please help
for those who have landed here as they were using private repositories or custom nuget feeds and RUN dotnet restore is failing ,then here is what you can do :
Applicable especially if : your NuGet.Config contains the private repo endpoint and credentials , then
copy your system's NuGet.Config in project folder at same root level where .csproject is.
now in docker file put these statements just before you try to restore package:
COPY ./NuGet.Config ./
after that , append the config file location in dotnet restore command like this :
RUN dotnet restore <CS_project_name>.csproj --configfile ./NuGet.Config
Now do rest of the thing which you wanted to do .
just at the end before entry point or before copying to other container(in case of multistage build) , it is good idea to remove NuGet.Config,as we don’t want that to be available in pod/container to be seen
RUN rm ./NuGet.Config
[Update] like mentioned at https://github.com/NuGet/Home/issues/4413#issuecomment-483920015
if we use the following copy command to put it in root of file system
COPY ./NuGet.Config /nuget.config
then we dont need to specify the location of config file during dotnet restore
In order for a dotnet
command running inside a container to find your custom feeds, the nuget.config
file must also be copied to the container.
To do this, add a nuget.config
file with your private feed to your project folder and add an additional COPY
step that copies this file to the container.
Example (Dockerfile):
WORKDIR ...
COPY NuGet.Config /
COPY ... ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With