Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy ASP.NET Core applications using Docker on Linux

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use Docker to deploy ASP.NET Core applications on Linux. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.

1. Create an application

Create an MVC application using ASP.NET Core and modify the Home Controller Index view code:

@{ ViewData["Title"] = "Home Page";} @*Welcome

Learn about building Web apps with ASP.NET Core.

*@ Deploying ASP.NET Core Applications with Docker

Run the program and the output is as shown below:

2. Add Dockerfile

Since we are using Docker for deployment, to add Dockerfile file, right click on the project, select "Add", then select "Docker Support", as shown in the figure:

We are deploying on Linux, so the target OS is Linux:

The Dockerfile file reads as follows:

#Use runtime mirror FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim# to set up working directory WORKDIR /app#Copy the contents of directory to current directory COPY . .# EXPOSE80#Set container encoding format ENV LANG C. UTF-8#Set time zone to solve the problem of inconsistent time between container and host RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime & echo 'Asia/Shanghai' >/etc/timezone#Run image entry command and executable file name ENTRYPOINT ["dotnet", "DockerDemo.dll"]

Note: After adding the Dockerfile file, a file content will be automatically added. The default Dockerfile content is not used here. The Dockerfile content can be modified by itself.

Modify Dockerfile attributes to Always Copy:

3. Release

Finally, publish the application, here select Publish to folder:

Publishing folder directories can be customized:

II. Deployment

Copy the files published in the above steps to a remote Linux server and deploy them.

1. Build a mirror

Execute the following command to build an image from the Dockerfile file:

docker build -t dockerdemo .

As shown in the figure:

Note: the last "... "It cannot be omitted.

By default, we will find the Dockerfile file under the current directory. We can also modify the name of the Dockerfile file. When building the image, use the-f parameter to specify which Dockerfile file to use. We can modify the name of the Dockerfile file:

Build the mirror using the following command:

docker build -t dockerdemotest -f Dockerfile-test .

As shown in the figure:

2. Operation container

Run the container using the image built from the above steps with the following command:

docker run --name=dockerdemo -d -p 5000:80 dockerdemo

As shown in the figure:

This means that the container runs successfully and you can access:

A simple deployment like this is done.

About "how to use Docker to deploy ASP.NET Core applications on Linux" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report