Working With .NET Core Web Containers
This article show you how to customize a .NET Core + SDK container to run an example application.
The first step is to create a container running the .NET Core + SDK web image. When you do, create an SSH/SFTP User as well.
Method 1: Build, Test, and Debug on the Container
Then the overall process is:
- Connect to the Container and build a .NET Core project.
- Publish the web application.
- Adjust the Container configuration to start the application on boot.
- Test the application.
Creating and Building the App
We’re going to mostly follow Microsoft’s get started with ASP.NET Core MVC documentation, and adapt to Webslice Containers as we go.
- SSH into the Container.
- Create a project using the
mvc
template. - Remove the existing example application.
- Publish the project into the
/container/application
directory.
The example code below uses the project name “CustomApp”. A directory with that name is created, and project files should be under ~/CustomApp
. The published application files should reside in the /container/application/
directory.
Configuring the Container
Once the application is published, you can configure Supervisor to start the application up on boot. The supervisord.conf
configuration file has a section named [program:dotnetapp]
that you can can use as a reference.
You can comment out the line and replace the default command
for this program to start the application that you just created. Here is what the configuration file should look like:
To apply your configuration changes, reboot the Container.
Test Your Changes and Debug
After your Container has restarted, check the website on a browser. If it is not working as expected, follow the dotnetapp
program logs and debug through your SSH session.
After every change to the project files you want to deploy, you must publish the application and reboot the Container again. Unless you change the project name, you won’t need to update the Supervisor configuration.
Method 2: Build and test Locally, Then Deploy to Your Container
To avoid putting an unnecessary load on your Webslice Containers server, you can store application project files on your workstation. By building and testing locally on aan Integrated Development Environment (IDE) you don’t involve your Container or its server until you’re ready to publish.
Webslice Containers are based on Linux, so once your application is developed and tested, ensure that it’s published to run on Linux. Read more in Microsoft’s’ dotnet publish documentation.
After publishing your application, SSH into your Container’s and upload it to the /container/application/
directory. on the Container. Then make any required changes to the supervisord.conf
configuration file (see “Configuring the Container” above). As always, reboot the Container to apply your changes.