Runar Ovesen Hjerpbakk

Software Philosopher

.dockerignore is your friend - remember to use it

While working on a particular project built with a multi-stage Dockerfile I got this error:

Step 13/19 : RUN dotnet test "./DashboardServerTests/DashboardServerTests.csproj" -c Release --no-restore
 ---> Running in ac850e55464c
Build started, please wait...
/usr/share/dotnet/sdk/2.0.3/Sdks/Microsoft.NET.Sdk/build/Microsoft.PackageDependencyResolution.targets(323,5): error : Assets file '/Users/sankra/projects/DashboardServer/Grafana/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/source/Grafana/Grafana.csproj]

The problem only appeared if the project was previously built on disk. After Clean, the build ran fine through Docker too.

Thus, the solution is to start clean and be thankful that .dockerignore exists.

In a .dockerignore, you can specify ignore rules and exceptions from these rules for files and folder. These won’t be included in the build context and thus won’t be visible to Docker while building from the Dockerfile.

For this specific project, my .dockerignore looks like this:

**/obj/
**/bin/

.dockerignore is your friend.

This will skip all bin and obj folders, making every build a clean build.