April 04, 2018 by Anuraj Estimated read time : 4 mins
Few days back I wrote a post about working with Angular 4 in ASP.NET MVC. I received multiple queries on deployment aspects - how to setup the development environment or how to deploy it in IIS, or in Azure etc. In this post I am explaining how to deploy a ASP.NET MVC - Angular application to Docker environment.
In the first section, I deploying the published version of the application to Docker. I already posted the source code for this already available in GitHub.
Firstly, you need to modify the project file to copy the output folder of Angular (In my scenario, I am using bundles folder) to the publish folder, so I added a MSBuild steps to do this.
In this build step, I am copying all the files from bundles folder to the publish folder. You may also need one more build step to compile the angular project, you can add one more build step to do this.
Next you need to create the Docker file to deploy the output folder to C:\Inetpub\wwwroot in the container. You can do it like this.
For database, now I am using SQL Server in my host machine. And to build SQL Database, I am using Database.SetInitializer() method in DbContext class. Here is the code for DbContext class.
Next you need to build the container and run it. Once it is running, you can do a docker inspect command and identify the IP Address of the container.
Here is the app running in my machine.
Next, I am building a Dockerfile, in which we are building the project - both ASP.NET MVC and Angular.
In this Dockerfile first I am downloading MSBuild, nuget and Node JS. Once downloaded, I am extracting nodejs, to C:\NodeJs folder. Then I am installing MS Build with MSBuildTools and WebBuildTools. Once both installations is done, I am setting the tools to the PATH.
You can run npm install in the dockerfile, but it will take sometime. So I ran npm install in my developer machine and I am copying the files to C:\Source folder in the container. Also I removed the ng build step from the project file, and I am running it outside. After building the Angular project, I am restoring the nuget packages with nuget.exe. And finally, I am building and deploying the solution with MSBuild.exe. For deploying I am using Visual Studio profile file. It is a simple pubxml file with FileSystem and deploying the output to C:\Inetpub\wwwroot directory. Here is the FolderProfile.pubxml file.
Please let me know if you’re facing any issues in running the application in Docker.