导航

Docker 制作WebApi镜像(.NetCore)

Posted on 2021-03-26 11:06  杨彬Allen  阅读(277)  评论(0编辑  收藏  举报

目录

安装步骤

1、将发布好的webapi文件拷贝到linux服务器上;

2、在根目录新增Dockerfile文件;

3、在Dockerfile中编写文件:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic AS base
RUN apt-get update && apt-get install -y libgdiplus
WORKDIR /app
COPY . /app
EXPOSE 80
ENTRYPOINT ["dotnet", "Medusa.Service.Platform.Entrance.dll"]

PS:需注意,此处有2个坑

3.1、.netcore的版本,需要拉取和你代码版本一致的,同时这里面还有一个sql server连不上的bug:connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 An internal exception was caught),那么你需要把FROM的改成下面这一句:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic AS base

3.2、我们的登录页用到了验证码,属于字节流,需要把libgdiplus的包也给打上

RUN apt-get update && apt-get install -y libgdiplus

  4、在Dockerfile所在目录运行image打包脚本,注意此处的.不能少

docker build -t medusa.service.platform:v1 .

  5、运行容器:todo

docker run --name dockerplatform -p 8805:80 -d medusa.service.platform:v1