Tuesday, June 20, 2017

This is likely going to be a quick post. I wanted to have a Docker Container running ASP.NET Core Web Application powered by React and Redux. Luckily there are nice SPA templates introduced by Microsoft, and there we have React, Redux template.

MVC ASP.NET Core with React.js and Redux

I created the application and did a publish. Then I have added a Dockerfile with following configs.

Right now I have a Docker support enabled ASP.NET Core MVC Application created (If you don't know how, you can read my above mentioned previous post).

Note: I have created the solution using Visual Studio 2017, but you don't need to have Visual Studio 2017 to create this solution. dotnet SDK and Visual Studio Code should be more than enough. For the next steps, we only need dotnet SDK and cmd/PowerShell.

Let's proceed. I have a clean solution, no obj/bin folders present yet.

No obj/bin folders

I have a PowerShell window opened on the root folder level.

PS C:\Users\Jaliya\Desktop\DockerComposeWebApp>

Next to do a Release build what I would do is do a dotnet restore and a publish like below.

But in that case the build would be done on my local machine, instead here I want to use a Docker Container to do the building.

Now let’s open up the docker-compose.ci.build.yml in my local folder. Remember I did not write this file myself, Visual Studio 2017 created this for me when I have enabled Docker Support for my project (if you want to know how to get these docker-compose.xxxxx.yml files created when using Visual Studio Code, you can read this previous post of mine Running ASP.NET Core MVC Application inside a Docker Linux Container from Windows).

Here you can see that we have a service named ci-build which uses microsoft/aspnetcore-build Image and that is the official Image for building ASP.NET Core applications (version will be changed time to time). Then my current folder is getting mapped to src folder in the ci-build Container (which is not yet created). After Container is created and running, it’s working directory will get changed to src and the given command will get executed. And basically what the command does is a dotnet restore and a dotnet publish (here output path is set to .\obj\Docker\publish).