【问题标题】:Running docker containers with .net6使用 .net6 运行 docker 容器
【发布时间】:2022-08-14 17:33:05
【问题描述】:

我目前正在使用 .net6 构建一个 API 示例,并且我正在跟踪使用 docker 来运行 API。

我的 docker 文件如下所示:

# Grab the app package and create a new build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
# Let\'s add all the files into the app directory
WORKDIR /app

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT [\"dotnet\", \"DotNet.Docker.dll\"]

我通过运行以下命令创建了图像:

 docker build -t binarythistle/dockerapi .    

现在,我正在尝试运行图像来创建容器:

docker run -p 8000:80 dockerapi  

但是,我得到以下结果:

The command could not be loaded, possibly because:
  * You intended to execute a .NET application:
      The application \'DotNet.Docker.dll\' does not exist.
  * You intended to execute a .NET SDK command:
      No .NET SDKs were found.

Download a .NET SDK:
https://aka.ms/dotnet-download

Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found

有谁知道可以做些什么来解决这个问题?

站点注释:我按照推荐下载了 .NET6.0 SDK macOS,但我仍然遇到问题。我正在使用 .net 运行的项目是一个标准 api 项目,其中允许我创建它的命令如下:

dotnet new webapi -n DockerAPI

    标签: c# .net docker .net-core dockerfile


    【解决方案1】:

    在您运行dotnet 的那个目录中没有DotNet.Docker.dll

    解决这个问题的最好方法是进入你刚刚创建的容器

    docker run -it dockerapi bash
    

    -it 将使其成为交互式进程 bash 将 ENTRYPOINT 更改为 bash

    一旦你有了一个 shell 然后运行 ​​ls 命令并查看从 docker build 中的上一层复制了哪些文件

    ls
    

    【讨论】:

      【解决方案2】:

      试试这个复制命令

      COPY --from=build-env /out .
      

      【讨论】:

        猜你喜欢
        • 2019-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-04
        • 1970-01-01
        • 2022-10-06
        • 1970-01-01
        相关资源
        最近更新 更多