Use Docker run .NetCore project on CentOS 7

Installation Docker

CentOS 7 installation Docker

Write Dockerfile

Right Project - "add -" Docker Support

Select Linux

Amended as follows:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 8080
COPY . /app
ENTRYPOINT ["dotnet", "demo.dll"]

Then put the files on the root directory publishing

Construction of Docker Mirror

 Use the terminal enters publish the file, execute the command:

docker build -t aspnetcore2.2docker .

Name: aspnetcore2.2docker, the last input  . in order to find  Dockerfile  file

 It appears Successfully behalf of success.

Query local mirror

docker images

Run-time image

By running the command

docker run --name demo -d -p 8080:8080 aspnetcore2.2docker

 -d 后台运行
 -p  端口映射 格式为:主机(宿主)端口:容器端口
 --name 容器名称
最后一个是名为 aspnetcore2.2docker 的镜像

查询本地正在运行的容器

docker ps

验证

浏览器中输入:http://ip:8080/api/values,就能看到以下页面:

Guess you like

Origin www.cnblogs.com/tenghao510/p/12001949.html