ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-enabled, Internet-connected apps. It is a cross-platform successor to .NET Framework. Ability to develop and run on Windows, macOS, and Linux.
But everyone tends to run the application in Windows only. Lets us consider a scenario that your application will be installing in both windows and linux platforms and when you want to test some packages ( say for example DinkToPdf — open-source package for converting HTML to PDF) across all the platforms to make sure the particular package is working in our application, at the time, the below steps can be found very useful to test in Linux environment.
Let's see how to do it. The prerequisite is Docker should be installed in Windows System through Oracle Virtual Box. Already I shared the steps in my previous blogs, see here for reference.
Step 1
Let's prepare your working environment by creating a new ASP.NET Core Project.
Step 2
Make sure you check the “Enable Docker Support” checkbox. This will create a dockerfile for you in the solution.
Step 3
Visual Studio will create you a project that looks something like this.
Step 4
Let’s run the project with IIS Express to make sure that everything is working normally. You should see something like this.
Step 5
The default dockerfile created from the ASP.NET Core template is pretty close to what we actually want. It uses one container to build and publish the app, then a second container to run it. Here is the default file.
Step 6
Now you can push this code to the oracle virtual box Linux system through git or through any FTP mechanism.
Step 7
From the cloned folder, build the docker file with the help of the docker build command.
docker build . -f WebApplication1/Dockerfile -t linuxdemo:latest
Step 8
Docker image is built and successfully tagged.
Step 9
Now run the docker image with the help of docker run command.
docker run -d -p 8080:80 linuxdemo:latest
Step 10
Now let's try to browse the application using the IP address(192.168.1.12) of the virtual machine and the port(8080) published with the endpoint.
So testing the asp.net core application in Linux environment is made easy with the help of the docker :)
Github: https://github.com/karthickcse05/pdfdemo-dotnetcore