Docker: are the build and publish stages required by container tools?

RdJNL 36 Reputation points
2022-01-16T13:47:31+00:00

When adding Docker support to a C# project, you'll automatically get a Dockerfile with 4 stages: base, build, publish, final. I know what the base and final stages are for, and I get that the build/publish has to happen in a separate stage in order to not have the full SDK in the final image.

But is there any requirement by VS for the build/publish to be in 2 separate stages?

I think the default Dockerfile's build stage is kinda useless, because the publish will build the project again. I want to change this, but I'm not sure if VS will have issues with that.

Developer technologies | C#
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Ken Tucker 5,861 Reputation points
    2022-01-16T21:42:44.24+00:00

    This article here gives a good explanation on how the container is built

    https://learn.microsoft.com/en-us/visualstudio/containers/container-build?view=vs-2019&WT.mc_id=visualstudio_containers_aka_containerfastmode

    Basically build uses the .net sdk to build the project instead of the asp.net sdk. The publish step moves only what is needed for the website to keep the container size smaller.


  2. Bruce (SqlWork.com) 78,161 Reputation points Volunteer Moderator
    2022-11-04T19:54:39.303+00:00

    for a trivial project you could drop the build step. but if the project references other projects that also need to be built, or you have complex build steps, then you don't want to simplify. you also might want also want to add a unit test step.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.