netcore的dockerfile编写部分要注意的地方

这里天研究netcore3.1部署在docker中,期间遇见了很多坑,下面大概讲一下安装过程

1.vs添加一个docker支持会生成一个dockerfile文件,但是那里面的代码很多如果你用打包到文件夹的方式的话我觉得是不需要的,所以对dockerfile文件修改如下:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN apt-get update
RUN apt-get -y install telnet
RUN apt-get -y install iputils-ping
RUN apt-get -y install vim
COPY . .

ENTRYPOINT ["dotnet", "Tourism.Api.dll"]

这里

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base需要时间很长,最好这之前确保你配置了docker镜像加速,并且如果你选择
mcr.microsoft.com/dotnet/core/runtime或者
mcr.microsoft.com/dotnet/core/sdk的话,应该都是会有问题的
依据这个文件
docker build -t api .
然后使用它构建一个容器的时候进入容器会在/app目录下,
这里因为没有vi、ping、telnet等命令,有时候需要进入测试一下网速修改个配置什么的不太方便,而且dotnet的镜像是根据debian的系统做出来的,所以不能用rpm或者yum,即使你是centos的系统,
这是一个坑点,解决了如何在镜像中用一些linux 的基础命令和如何安装基础命令,可能会出现

 debconf: delaying package configuration, since apt-utils is not installed

这样的警告,注意,他不是错误,只是警告,具体可以谷歌一下,这个像我这里只是安装一点点常用的linux命令,所以我不用管这些警告,我可以正常使用,到此,一个基本的镜像就做好了

原文地址:https://www.cnblogs.com/llcdbk/p/12202544.html