skip to Main Content

I am trying to create a simple ASP.NET Core web application with React (using the "ASP.NET Core with React.js" template). Further I want to containerize it.

If I run the release configuration, everything works fine. If I run the debug configuration, it seems like the environment variables are not set properly and the npm project is not set up.

As far as I researched, this makes completely sense, as Visual Studio / MSBuild is not execution all stages when building using the debug configuration.

I tried the following steps:

  • Adding <ContainerDevelopmentMode>Regular</ContainerDevelopmentMode>
  • Adding <DockerfileFastModeStage>final</DockerfileFastModeStage>
  • Removing all docker images, volumes and containers

I figured out, that everything I add to the Base-Stage will be applied to the debug container. But that doesn’t make any sense to me.

Which stages are actually included in the image used be Visual Studio / MSBuild? If not all stages are executed, how is the source code passed into the image/container? What entry point is used internally, if only the base stage is built?

My Dockerfile:

#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y libpng-dev libjpeg-dev curl libxi6 build-essential libgl1-mesa-glx
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash -
RUN apt-get install -y nodejs

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y libpng-dev libjpeg-dev curl libxi6 build-essential libgl1-mesa-glx
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash -
RUN apt-get install -y nodejs
COPY ["WebsiteLogos/WebsiteLogos.csproj", "WebsiteLogos/"]
RUN dotnet restore "WebsiteLogos/WebsiteLogos.csproj"
COPY . .
WORKDIR "/src/WebsiteLogos"
RUN dotnet build "WebsiteLogos.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WebsiteLogos.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM node:16 AS build-web
COPY ./WebsiteLogos/ClientApp/package.json /WebsiteLogos/ClientApp/package.json
COPY ./WebsiteLogos/ClientApp/package-lock.json /WebsiteLogos/ClientApp/package-lock.json
WORKDIR /WebsiteLogos/ClientApp
RUN npm ci
COPY ./WebsiteLogos/ClientApp/ /WebsiteLogos/ClientApp
RUN npm run build

FROM base AS final
WORKDIR /app
ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.AspNetCore.SpaProxy
COPY --from=publish /app/publish .
COPY --from=build-web /WebsiteLogos/ClientApp/build ./ClientApp/build
ENTRYPOINT ["dotnet", "WebsiteLogos.dll"]

2

Answers


  1. Chosen as BEST ANSWER

    Figured it out myself. MSBuild generates an additional obj/Docker/docker-compose.vs.debug.g.yml, which defines this stuff.

    Which stages are actually included in the image used be Visual Studio / MSBuild?

    • The target image is "base" because this is specified in the additional compose file.

    If not all stages are executed, how is the source code passed into the image/container?

    • The code is compiled locally and mounted to the container as an volume

    What entry point is used internally, if only the base stage is built?

    • I don't know how the code is actually executed, but the entry point is specified as "entrypoint: tail -f /dev/null" in the docker-compose file

  2. For instructions on how VS interacts with the different stages of the dockerfile see: https://aka.ms/customizecontainer

    For instructions on configuring the compose specific flow see: Docker Compose build settings

    To your specific questions:
    Which stages are actually included in the image used be Visual Studio / MSBuild?
    When using fast mode, the 1st stage is used by default, otherwise it can be configured using DockerfileFastModeStage for running a single container for a project, or specifying the stage in docker-compose.vs.debug.yml for a .dcproj.

    If not all stages are executed, how is the source code passed into the image/container?
    For fast mode, VS generates volume mounts to include the source and the built binaries for the project in the container.

    What entry point is used internally, if only the base stage is built?
    To enable starting under the debugger the container’s entrypoint is overridden with tail -f /dev/null.
    To control what is started by the debugger you can set DockerDebuggee* (docs) for starting a single project or the labels com.microsoft.visualstudio.debuggee.* (docs) for a compose project.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search