我是使用 docker 的新手,在基于 .net core 5.0 的 docker 中安装 python 时遇到问题,我遵循简单的教程并将其成功应用于服务器。我正在尝试应用它在 Visual Studio(.net core 5.0)中制作我自己的 docker 文件
我的开发(部署)环境基于 .net core 和 python 3.8。
我正在使用Visual Studio 提供的docker 支持。如果我使用此选项,Visual Studio 将为我的项目创建一个 Dockerfile。
下面是初始生成的 docker 文件。
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["testApp/testApp.csproj", "testApp/"]
COPY ["Util/Util.csproj", "Util/"]
RUN dotnet restore "testApp/testApp.csproj"
COPY . .
WORKDIR "/src/testApp"
RUN dotnet build "testApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "testApp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "testApp.dll"]
我添加了一些脚本来将 python3.8 安装到 Docker。下面是添加我的代码的脚本(请参阅#mycode start - end)
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
#mycode start - python install
RUN apt-get update -y && apt-get install python3 -y
COPY requirements.txt ./
RUN pip install --upgrade pip && \
pip install -y -r requirements.txt
COPY . .
#mycode end
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["testApp/testApp.csproj", "testApp/"]
COPY ["Util/Util.csproj", "Util/"]
RUN dotnet restore "testApp/testApp.csproj"
COPY . .
WORKDIR "/src/testApp"
RUN dotnet build "testApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "testApp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "testApp.dll"]
当我使用这个脚本构建时,我看到了一个错误
#8 [base 3/5] COPY requirements.txt ./
#8 sha256:29112b53fcb5ccf9ccc50257780a731276
#8 ERROR: "/requirements.txt" not found: not found
requirements.txt 的路径如下。
C:\
project
testApp
testApp
testApp.csproj
startup.cs
Dockerfile
requirements.txt
Util
Util.csproj
Util.cs
你能帮我解决它吗?请让我知道有什么问题。
感谢您阅读。