Docker deployment. Net core 3.1 (Chapter 2)

Time:2020-10-31

  
The previous chapter described how to install docker and pull images【 https://www.cnblogs.com/smile-live/p/13596861.html 】The basic environment has been set up. Here is how to deploy the. Net core project

1. Create a new. Net core project (version 3.1 is used here). This function can run and access it
  

 

 

 

  

 

 

 

2. Publish the project and upload it to Linux_ A this path is self built]
  

 

3. Pull the image of. Net core3.1: docker pull mcr.microsoft.com/dotnet/core/aspnet : 3.1 [this process is relatively slow and patient]
    

 

 

After pulling, enter docker images to view all images. The red box below shows success
    

4. Create a dockerfile named file. Do not have a suffix. Put it in / Smile / smile_ A under the path of [your own project path], this file has the following contents:

    FROM mcr.microsoft.com/dotnet/core/aspnet :3.1【 mcr.microsoft.com/dotnet/core/aspnet : 3.1 the image name is the name in the red box in point 3]
    RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    WORKDIR /app
    COPY . .
    ENTRYPOINT [“dotnet”, ” SmileLinuxPush.dll “]【 SmileLinuxPush.dll Is the DLL name of your project]
    

 

5. Input: CD / Smile / smile_ a  
    

 

 

6. Create image: docker build – t netcore-smile-c
      

 

 

After success, enter docker images to view the image
    

 

 

7. Generate container, visit the website: docker run — name smile-c — restart = always – P 5100:5100 – D netcore-smile-c
Smile-c: Custom container name
Netcore-smile-c: image generated by current project [point 6]

— restart = always: when docker restarts, the container starts automatically
5100:5100: indicates the mapping between external port and internal container port [external port, point 1]

8. View all containers: docker PS – A

    

Visit http://:5100