Use Local Nuget Feed in Dockerfile

Don't forget the locals

Posted by admin on April 25, 2024

"It works on my machine" but not when I'd build a docker image and using it in production.

Story of my life.

The Symptom

Changes I'd make and run locally worked as expected on my dev machine. But when I'd deploy them to production, they wouldn't be there.

More Context

More specifically, I was forked an open source library to make a change I needed.

I then rebuilt the Nuget package, stored it in a local nuget repository source and referenced that local nuget package in my app.

I would run the app locally on my dev machine and, boom, the change works flawlessly.

To move the change to production, I built a new docker image and deployed that new image to the production server.

AHHHH!!! The change wouldn't show up, even though I know I'm running the new image.

The Problem

After many hours of insanity, quite literally trying the same thing over and over expecting different results, I finally realized the cause of my problem.

The Dockerfile I used to build the docker container has no knowledge or access to the local nuget feed on my dev machine.

Why did it take so long to realize this?

Because the opensource library I was using is available publicly on And the source of my frustration was that I did NOT, I repeat, I DID NOT, use a different/unique/not-currently-used-on-nuget-dot-org version number (laziness, I guess).

So, everything build without error. But the build process would grab the nuget package from which did NOT have my changes that I packaged into the local nuget feed version of the same library.

The Solution

I solved this problem by

  1. Copying the local nuget feed packages to a folder in the root of my git repository.
  2. Adding a COPY instruction to the Dockerfile to ensure that the local nuget packages are availble during the build step of the docker build.
  3. Adding a RUN nuget add source command to add the local nuget feed as a nuget package source during the docker build.

After I made that change, the new docker image work as expected in the production environment.

If you found value in this post, consider following me on X @davidpuplava for more valuable information about Game Dev, OrchardCore, C#/.NET and other topics.