I had 3 questions when I published the ASP.
1. Why the published program cannot run in a Docker container
When published in the Window development environment, dotnet Xxx.dll can run normally, but after it is placed in the Docker container, it is reported *.*.deps.json not found error. After the following article resolved the problem: https://www.cnblogs.com/mahidol/p/9064943.html
Based on the conclusion of the above article, only the Code and resources in the project are published because the environment in which it is published is considered to contain the required libraries.
The base image for my dockerfile is: Microsoft/dotnet:2.1.2-aspnetcore-runtime, so the ASP. NET core runtime is complete, so the previous release should be missing the required files on the Linux system. So reset the publishing options, such as:
Is the program released now running well in the Docker container?
2. Issue of volume of documents released
Following a solution to a problem, create a new ASP. NET core project to publish the settings as follows:
Only a simple example of the program, published there is 90M. A little too scary??, this release of the program should be able to run directly on the Linux machine without the ASP-runtime (I did not test).
3. Program Port Configuration
The program runs in a Linux or Docker container and requires that we have a clear port. Originally ASP. NET core default 5000 port, I tested in the container to listen to 80 ports. According to the information on the Internet, modify the port configuration found invalid, modify the steps as follows (which friend modified successfully, please let me know, thank you):
New Hosting.json
{ "Server.urls": "http://localhost:9000; "}
Modify Program.cs
Public classProgram { Public Static voidMain (string[] args) { varConfig =NewConfigurationbuilder (). Setbasepath (Directory.GetCurrentDirectory ()). Addjsonfile ("Hosting.json", Optional:true) . Build (); Buildwebhost (args, config). Run (); } Public StaticIwebhost Buildwebhost (string[] args, iconfigurationroot config) =Webhost.createdefaultbuilder (args). Useconfiguration (config). Usestartup<Startup>() . Build (); }
Final severe spat 2 ms
1, the controller has the following code:
Public class Testcontroller:controller { public iactionresult Home () { new"123" ; return View (); } }
The view code is as follows:
@{ viewdata["Title" = "Home page";} @ViewBag. Px.name
Direct error:
2. Output Chinese in view
The controller has the following code:
public class Testcontroller:controller { public iactionresult Home () { VIEWBAG.TXT = "abc" ;//"Hello"; return View (); } }
The view code is as follows:
@{ viewdata["Title" = "Home page";} < Script > var ="@ViewBag. Txt"; alert (x); </ Script >
Results of "abc" and "Hello" output:
The file size is too large and the configuration of the service port is questionable when ASP. NET core is published to the Docker container