dotnet restore fails with NU1301 inside docker build
error NU1301: Unable to load the service index for sourceShort answer
NU1301 means restore could not use one of the configured package sources. In a docker build the usual reasons are a source in nuget.config that does not exist in the container, a proxy the build does not know about, or DNS that fails inside the container. Read the line after NU1301 to see which source failed, then fix that one.
Fix it fast
1Find out which cause you have
Run the restore step alone with detailed output so the failing source URL or path is printed, then compare it to the sources in your nuget.config.
dotnet restore --verbosity detailed cat nuget.config2Match what you see, then jump to its fix
- 1
NU1301 names a local path such as C:\... or a feed on a private network, and the message says the source does not exist or cannot be reached.A source in nuget.config does not exist inside the containerFix - 2
The failing source is a normal https address such as api.nuget.org, and the same restore works on a machine outside the proxy.The build sits behind a proxy and restore does not use itFix - 3
The host can open the feed URL in a browser, but the container cannot resolve its name.Name lookup fails inside the containerFix
- 1
What does the error look like?
error NU1301: Unable to load the service index for sourceNU1301: The local source 'C:\Code\Contoso\contosoLocalSource' doesn't exist.
Cause 1 of 3
A source in nuget.config does not exist inside the container
1Check
A nuget.config copied into the build context is read by restore in the container. A Windows folder path or a private feed address that only works on your machine fails there.
cat nuget.config2Fix
Microsoft's guidance for NU1301 is to remove a source the build does not need. Put a clear element first so machine-specific sources are ignored, then list only the sources the container can reach.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>3Verify
Rebuild without the cache so the restore step really runs again.
docker build --no-cache --progress=plain -t my-app .Confirmed by learn.microsoft.com
Cause 2 of 3
The build sits behind a proxy and restore does not use it
1Check
NuGet reads http_proxy and no_proxy from nuget.config or from environment variables, and a build container does not receive your shell's variables by itself.
env | grep -i proxy2Fix
Pass the proxy values to the build as build arguments, which Docker accepts as predefined build arguments without an ARG line, or set http_proxy in the nuget.config used by the build.
docker build \
--build-arg HTTP_PROXY=http://proxy.example.com:3128 \
--build-arg HTTPS_PROXY=http://proxy.example.com:3128 \
--build-arg NO_PROXY=localhost,127.0.0.1 \
-t my-app .3Verify
The restore step finishes and the build moves on to compile.
docker build --progress=plain -t my-app .Confirmed by docs.docker.com
Cause 3 of 3
Name lookup fails inside the container
1Check
Containers use the host's DNS servers by default. A resolver on the host's loopback address, common with local DNS caches or VPN clients, does not work from inside a container, because 127.0.0.1 there is the container itself.
cat /etc/resolv.conf
docker run --rm mcr.microsoft.com/dotnet/sdk:9.0 getent hosts api.nuget.org2Fix
Give the daemon a DNS server the container can reach, or pass one to a single container with --dns to confirm the cause.
docker run --rm --dns 1.1.1.1 mcr.microsoft.com/dotnet/sdk:9.0 getent hosts api.nuget.org3Verify
The lookup returns an address, then the image builds.
docker build --progress=plain -t my-app .Confirmed by docs.docker.com
How do I stop it coming back?
- Commit a nuget.config with a clear element and only the sources a clean machine can reach.
- Restore in its own layer after copying only the project files, so a network failure shows up at the restore line.
- Keep private feed credentials out of the image; pass them as build secrets.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
Related fixes
Servers
MSB1011 when dotnet build or publish runs inside a Docker build
dotnet build or dotnet publish fails in a RUN step of the Dockerfile
dotnet build and dotnet publish pick a project by searching the current folder.
3 causes, each with a fixServers
A containerized ASP.NET Core app says the framework Microsoft.AspNetCore.App was not found
Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
The app asks for a shared framework the final image does not have.
3 causes, each with a fixServers
docker build cannot find a local file or log in to a private NuGet feed
The parameter is incorrect
A Docker build sees only the build context, minus anything in .dockerignore, so files outside it are not found.
4 causes, each with a fixServers
ASP.NET Core container does not answer on the published port
The container is running and logs no error, but the mapped host port never answers
Since .NET 8 the ASP.NET Core container images listen on port 8080, not 80.
3 causes, each with a fixServers
docker build fails with CS5001, no entry point found
error CS0017: Program has more than one entry point defined.
CS5001 means the compiler built an executable project and found no entry point.
4 causes, each with a fixServers
dotnet says it cannot find any installed .NET SDKs (in Docker or on a server)
A compatible .NET SDK was not found
The dotnet command found a runtime but no SDK that fits.
3 causes, each with a fix