.NET Core Docker Image for SPA Applications

前端 未结 6 1504
鱼传尺愫
鱼传尺愫 2020-12-08 16:05

What is the correct Docker image to use when creating a new ASP.NET Core MVC app, specifically with the React/Redux (or other Node.js required) template? If not a specific i

6条回答
  •  自闭症患者
    2020-12-08 16:24

    Based on @Daniels answer above, running Visual Studio 2017 v15.4 and ASP.NET Core 2.0 on Docker, here are the changes you need to make to allow correct Production and Development behavior for SPA applications (in my case I'm using Angular):

    • Add a new Dockerfile to your project which is a copy of the original. Lets call it Dockerfile.Development. Modify as follows:

      FROM microsoft/aspnetcore:2.0
      ARG source
      
      # BEGIN MODIFICATION - Node is needed for development (but not production)
      RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
      RUN apt-get install --assume-yes nodejs
      # END MODIFICATION
      
      WORKDIR /app
      EXPOSE 80
      COPY ${source:-obj/Docker/publish} .
      ENTRYPOINT ["dotnet", "MyService.dll"]
      
    • Modify the docker-compose.override.yml file in your solution to use this new dockerfile in development. It'll look something like this:

      version: '3'
      
      services:
        myservice:
          environment:
            - ASPNETCORE_ENVIRONMENT=Development
          ports:
            - "80"
          build:
            dockerfile: Dockerfile.Development
      
    • Modify the webpack.config.js file in your project to enable watching for changes, as follows:

      const clientBundleConfig = merge(sharedConfig, {
        entry: { 'main-client': './ClientApp/boot.browser.ts' },
        output: { path: path.join(__dirname, clientBundleOutputDir) },
        // BEGIN MODIFICATION
        watch: isDevBuild,
        watchOptions: {
          poll: isDevBuild ? 1000 : false
        },
        // END MODIFICATION
        plugins: [
          new webpack.DllReferencePlugin({
              context: __dirname,
              manifest: require('./wwwroot/dist/vendor-manifest.json')
          })
        ].concat(isDevBuild ? [
      

提交回复
热议问题