.NET Core 2.1 Centos 7 拒绝访问路径“/proc/1/map_files”

Access to the path '/proc/1/map_files' is denied .NET Core 2.1 Centos 7

我最近按照建议的升级指南将我的 .NET Core Web 应用程序项目升级到 .NET Core 2.1。

我还更新了我的 Docker 文件 - 一个使用 alpine 运行time 图像作为基础,另一个使用标准的 aspnet 运行time 图像作为基础。但是,当 运行 在 Docker 主机上 运行 在 Centos 7.4 上 运行ning 时,它们立即失败并显示消息 "Access to the path '/proc/1/map_files' is denied"。这些图像是在 运行 正在使用的同一台机器上构建的。

在Windows上构建&运行时没有问题。当在 Centos 上构建的图像被导入 Docker for Windows 时,它们 运行ning 很好。只有在Centos docker主机上才会出现这个问题。

我已经在 Github here, and found a similar issue here 上提交了一个问题,但给出的唯一解决方案是使用工作目录(我试过了,但没有成功)。

不知道这里发生了什么,但希望之前有人 运行 了解过这个。

docker 个文件是

FROM microsoft/dotnet:2.1.2-aspnetcore-runtime-alpine3.7
COPY /publish/ .
EXPOSE 5000/tcp
ENV ASPNETCORE_URLS http://*:5000

RUN mkdir web-data
RUN mkdir web-data/my-api

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

FROM microsoft/dotnet:2.1.2-aspnetcore-runtime
COPY /publish/ .
EXPOSE 5000/tcp
ENV ASPNETCORE_URLS http://*:5000

ENV REDIS_URL redis
ENV REDIS_PORT 6379
ENV REDIS_KEY_NAME DataProtection-Keys

ENV DP_CERT_PATH /etc/ssl/dotnet/dp-cert.pfx

RUN mkdir web-data
RUN mkdir web-data/my-app

# this is required in order to create Excel reports
RUN apt-get update
RUN apt-get install -y libgdiplus

ENTRYPOINT ["dotnet", "My.App.dll"]

docker运行命令如下

docker run -d -e ASPNETCORE_ENVIRONMENT=Dev -e DP_CERT_PASS=123xyz \
--name my-app --net app-web  \
--mount source=logs,target=/etc/logs --mount source=web-data,target=/web-data \
--mount source=dp-certs,target=/etc/ssl/dotnet \
--restart always my-app:1.0.0

已通过添加工作目录 /app 并在其中复制文件来解决此问题。但是我仍然不确定为什么它在 2.0 而不是 2.1 上工作,以及为什么它在 Docker 上 运行 对于 Windows 而不是 Docker 在 Centos 上。

您只需要在 Docker 文件

中添加此 "WORKDIR /app"

我正在编译 dotnet core 2.2 并将其打包到 Docker 在 CentOS7 服务器上运行,请参阅我的 Docker 文件,例如它对我来说工作正常:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-dotnetcore-sdk
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2

WORKDIR /app
COPY --from=build-dotnetcore-sdk /app/out .

ENTRYPOINT dotnet poc-dotnet-core-mvc.dll