release ASP.NET Core project
Publish the project to the target folder just like normal project Publishing
Build dockerfile file
Create a new dockerfile in the root directory of the target file (no suffix)
From Microsoft / dotnet // build image based on 'Microsoft / dotnet' Copy. / APP // copy all files in the project folder to the app folder in the docker container. Here are two parameters Workdir / APP // set the working directory to the '/ APP' folder, which is the default folder for container startup Expose 80 // set the docker container to expose 80 ports CMD ["dotnet", " Core.Web.dll "] // use 'dotnet core Web.dll 'to run the application
Upload project file
1. Build the project as an image
Upload the file to the WWW directory of Linux and use the command to build the image
Docker build - t testcore. // - t specifies the image name. Indicates the directory of dockerfile
Note that to build an image based on Microsoft / aspnetcore or Microsoft / dotnet in dockerfile (dotnet > aspnetcore), you need to distinguish the image version installed on the server
The construction is successful. You can see the new image in the image
2. Publish the image as a container
docker run --name testapp -d -p 8000:80 -v /www:/app testcore --Name specifies the container name -D specifies that the container runs in the background -P specifies that the external 8000 port is mapped to the container 80 port -Vbind data volume / www to / APP in container local directory must be absolute path Testcore image name
3. Check whether the container is running. If the startup failure is displayed as exit, you can check the log
Docker PS - A // view the running status of all containers Docker exec - it testapp bash // if the container is running, enter the container Docker logs testapp // if the container is not running, check the error log
4. Request the website to check whether the website runs successfully
curl 0.0.0.0:8000 curl -s -D - localhost:8000 -o /Dev / null // view the request return information
Finally, check the opening of the firewall port and the Alibaba cloud background security group port (if you are using Alibaba cloud services), and then visit the Internet
5. Update code
Since the data volume is mapped when the container is created, when there is a static file update, it will be automatically updated into the container.
But when there is a DLL file update, you need to restart the container manually
docker restart testapp
Above, the implementation of a Asp.Net The whole process of publishing core MVC project to docker. At present, there is only one dotnet image in the container, and the kestrel server is actually accessed directly through the address access website.
Some additional ideas
Kestrel server is only a lightweight web server and does not support host name based binding (if more than one server is deployed ASP.NET Core sites, each site needs to use a different port)
A reverse proxy server (IIS, nginx or APACHE) is required between kestrel and the Internet for security reasons (including but not limited to appropriate timeout, size restrictions, and concurrent connection restrictions)
Next, I’ll describe the problem I encountered when forwarding requests to kestrel using nginx.
The above is the whole content of this article. I hope that the content of this article has some reference learning value for your study or work. Thank you for your support for developepaer.