Use docker container to run .net core webapi
docker commonly used commands
- docker info | query docker basic information
- docker images | View all mirrors
- docker ps | queries all containers
- docker rmi | Remove one or more images
- docker rm | Remove one or more containers
- docker build | Build an image from a Dockerfile
- docker run | Run a command in a new container
- docker stop | Stop one or more running containers
- docker start | Start one or more stopped containers
- docker pull | Pull an image or a repository from a registry
cmd Create a project
Install .net core sdk
Check whether the installation was successful
C:\Users\jiangyi\myproj>dotnet -version
Unknown option: -version
.NET Core SDK (3.0.100)
New Project
C:\Users\jiangyi>dotnet new webapi -n myproj
The template "ASP.NET Core Web API" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on myproj\myproj.csproj...
C: \ Users \ jiangyi \ myproj \ myproj.csproj reduction completed in 88.66 ms.
Restore succeeded.
Build the project
cd to the project directory:
C:\Users\jiangyi>cd myproj
Compile build the project:
C:\Users\jiangyi\myproj>dotnet restore
C: \ Users \ jiangyi \ myproj \ myproj.csproj reduction completed in 30.56 ms.
In the run locally
C:\Users\jiangyi\myproj>dotnet run
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
Can be accessed through a browser https: // localhost: 5001
Create a mirror
ps: image name myprojimage for you to be output, followed by a note. ''
C:\Users\jiangyi\myproj>docker build -t myprojimage .
...
Build succeeded. 0 Warning(s) 0 Error(s)
Time Elapsed 00:00:03.15
Publish Project
ps: run-time image, the docker's release out port 80, port 8080 in external access
C:\Users\jiangyi\myproj>docker run -p 8080:80 myprojimage
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:80
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.