Docker Community Forums

Share and learn in the Docker community.

Ignore test projects on docker file


I have multiple projects within a solution, including test projects.
In the docker file, all projects are included to be able to build docker successfully (including the solution file).
I am aiming to remove test projects from the docker image. I tried to ignore test projects in build configuration manager (visual studio), I have to ignore in both debug and release mode to make docker build successfully. Ignoring on release mode only won’t build.

Is it possible to ignore on release mode only?
We do most of the development and local unit test in visual studio, so we would still want the test projects to build in the debug mode. It would be inconvenient to always changing the configuration manager or manually build the test project.

If we removed the test projects from docker build, would the unit tests still run in the bitbucket pipeline?

Any help is much appreciated. Thank you!

You need to add a .dockerignore file to your project that lists directories and files that should be ignored during build. Unfortunately, there is no way to define different .dockerignore on build.


But you can do what is called a multi-stage build where the tests are included in the “build” image part but then thrown away when you create the final image. See and if you are doing .NET.