In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "the .NET 5 deployment program runs on Docker". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Create a site
Create an ASP.NET Core Web application and check to enable Docker support. Automatically create a Dockerfile file for us.
2. Write Dockerfile files
Dockerfile is a configuration file in file format, and users can use dockerfile to quickly build custom images. Consists of line-by-line command statements and supports comment lines starting with #.
Dockerfile topic content is generally divided into four parts.
Basic image information
Maintainer information using label directive
Mirror operation instruction
Execute instructions when the container is started
# See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
# Depending on the operating system of the host machines (s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
# For more information, please see https://aka.ms/containercompat
# FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
# WORKDIR / app
# EXPOSE 80
# EXPOSE 443
#
# FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
# WORKDIR / src
# COPY ["AA.Mvc/AA.Mvc.csproj", "AA.Mvc/"]
# RUN dotnet restore "AA.Mvc/AA.Mvc.csproj"
# COPY. .
# WORKDIR "/ src/AA.Mvc"
# RUN dotnet build "AA.Mvc.csproj"-c Release-o / app/build
#
# FROM build AS publish
# RUN dotnet publish "AA.Mvc.csproj"-c Release-o / app/publish
#
# FROM base AS final
# WORKDIR / app
# COPY-from=publish / app/publish.
# ENTRYPOINT ["dotnet", "AA.Mvc.dll"]
# parent image
# FROM microsoft/aspnetcore:5.0
# FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS baseWORKDIR / app
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
# # setting working Directory
# WORKDIR / app
#
# # copy the release file to / app
# COPY. / app
#
# # setting Port
# EXPOSE 5005
EXPOSE 80
COPY. .
# use AA.Mvc.dll to run ASP.NET Core projects, pay attention to case
# ENTRYPOINT ["dotnet", "AA.Mvc.dll", "--server.urls", "http://*:5005"]"
ENTRYPOINT ["dotnet", "AA.Mvc.dll"]
The dockerfile file directive states:
FROM-specifies the base image of the created image
WORKDIR- configuration working directory
EXPOSE- declares the port on which the service listens in the image
COPY- copies content to the mirror
Default population command for ENTRYPOINT- to start the image
3. Compile and publish web project
Set up dockerfile file output replication
Release complete
4. Build the image, run the container and browse
To create an image, you can use the command docker build, as shown below:
Docker build-t core-mvc.
This step may be slower, because you need to download the runtime environment, please wait patiently
Parameter decomposition:
-t-specify the image name
At the end of the order. -indicates that the build context is the current directory. By default, docker will find the Dockerfile file in the root directory of the context.
View the list of images and enter the command
Docker images
Create and start, view containers
Docker run-- name netcore-mvc-d-p 50879 core-mvc
Docker ps-a
Parameter description
-d, indicating that the container is running in daemonized mode in the background
-p external ports are mapped to internal container ports.
-- name specifies the name of the container. Of course, it can not be specified, but it will be created for us by default.
Here, if you run docker run again after a failure, it will prompt that the name already exists. You can delete the container using the following command
Docker rm-f netcore-mvc
The last parameter, core-mvc, is the name of the image we just created. After the above four steps, enter the address http://localhost:50879/ in the browser to see the figure.
At this point, a complete project runs manually in the docker container.
This is the end of the content of ".NET 5 deployment program runs on Docker". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.