Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 Docker support not available for ASP.Net Core Angular or React projects

Does anyone have any insight as to why Visual Studio 2017 has a check box that enables Docker support for ASP.NET Core for Empty, Web API, Web Application and Web Application (MVC) templates, but not for the SPA templates Angular, React.js, or React.js and Redux?

Are there any resources showing how to add Docker support to these SPA templates? My google-fu is strong, but I can't find any.

like image 994
Adam Vincent Avatar asked Oct 20 '17 12:10

Adam Vincent


People also ask

How do I add Docker support to an existing project in Visual Studio?

Existing app Open the project in Visual Studio, and choose one of the following options: Select Docker Support from the Project menu. Right-click the project in Solution Explorer and select Add > Docker Support.

Can ASP NET application be run in Docker container?

Choose the docker option to run the application as shown in the following image. After clicking on the docker option, it will build code, create a docker image as well as a docker container and run the application inside the docker container without using the docker commands on the windows command prompt.

Can I use react with ASP.NET Core?

The project template creates an ASP.NET Core app and a React app. The ASP.NET Core app is intended to be used for data access, authorization, and other server-side concerns. The React app, residing in the ClientApp subdirectory, is intended to be used for all UI concerns.


1 Answers

The reason you are seeing that error is that for SPA projects, the csproj contains commands to run steps defined in the package.json to do packaging (ng build, webpack, etc.). And that requires Node to be INSIDE the build container that needs to be added explicitly. You will have to ensure that the Node version you use in the container will work with the build image that you have chosen. Most times it should not be an issue, but in case it is at least you are now aware.

You will need to add the following to the Dockerfile after the dotnet build and before the dotnet publish steps as below. My example uses Node 10.13 since that is what is supported by the build image that we pull for Azure Container deployments.

RUN dotnet build ...

# **** Adding Node - Start
ADD https://nodejs.org/dist/v10.13.0/node-v10.13.0-win-x64.zip "C:\build\node-v10.13.0-win-x64.zip"
RUN PowerShell Expand-Archive C:\build\node-v10.13.0-win-x64.zip C:/
RUN PowerShell Rename-Item C:\node-v10.13.0-win-x64 node
RUN SETX PATH C:\node
ENTRYPOINT C:\node\node.exe
# **** Adding Node - End

FROM build AS publish
RUN dotnet publish ...
like image 107
Himanshu Swami Avatar answered Sep 22 '22 06:09

Himanshu Swami