【问题标题】:Making docker container run properly使 docker 容器正常运行
【发布时间】:2021-09-14 14:44:24
【问题描述】:

我正在编写 docker 容器。我站起来了,但在我看来,它不起作用。 我想运行 dotnet 应用程序,它使用 rabbitmq 进行通信。运行命令后: 'docker-compose logs mlmodule' 它不显示任何日志(但它应该)。 我认为这是由错误的图像代码引起的。我是 docker 和 docker-compose 的新手。

这是图片的代码

#docker base SDK image
FROM mcr.microsoft.com/dotnet/sdk:5.0 as build-env
WORKDIR mlmodule
#copy the CSPROJ file and restore any dependecies
COPY mlmodule/*.csproj ./
RUN dotnet restore
#copy project files and build release
COPY / ./
RUN dotnet publish mlmodule.sln -c Release -o out
#Generate runtime image
FROM mcr.microsoft.com/dotnet/runtime:5.0.9-alpine3.13-amd64
WORKDIR mlmodule
COPY --from=build-env mlmodule/out .

这就是 docker-compose 的代码:

rabbitmq:
image: rabbitmq:3-management-alpine
container_name: 'rabbitmq'
ports:
  - 5672:5672
  - 15672:15672
volumes:
  - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
  - ~/.docker-conf/rabbitmq/data/:/var/log/rabbitmq/
networks:
  - rabbitmq_go_net


ml-module:
build: ./mlmodule/
container_name: ml-module
environment:
  CLOUDSDK_PYTHON: /usr/bin/python3
  LD_LIBRARY_PATH: /usr/local/lib
depends_on:
  - rabbitmq
tty: true
networks:
  - rabbitmq_go_net

编辑:

我已经修复了 rabbitmq 容器,现在我看到了日志:

 ml-module    | Could not execute because the specified command or file was not found.
 ml-module    | Possible reasons for this include:
 ml-module    |   * You misspelled a built-in dotnet command.
 ml-module    |   * You intended to execute a .NET program, but dotnet-MLModule.sln does not exist.
 ml-module    |   * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

【问题讨论】:

  • 同一个应用程序确实产生输出是否存在另一个环境?顺便提到了 Python。核心应用程序是 Python 还是 C#? environment: 设置对我来说似乎很可疑;您通常不需要手动指定networks:container_name:;但是对于 RabbitMQ,您通常应该指定 hostname: 以免它在重新启动时放错数据。
  • docker-compose logs mlmodule 命令是否产生了它自己的错误或者什么也不输出并转到下一行?尝试运行下一个命令docker-compose logs ml-module
  • @DavidMaze 1. mlmodule 是 dotnet 应用程序,当我在 vsc ide 上运行它时,它会生成日志。核心应用程序是用 java 编写的。 2.我提到python路径是因为它是必需的,当它不存在时,应用程序抛出“找不到Open_ssl路径”。 3 我的应用程序包含更多容器,我想将它们与其他容器隔离,这就是我指定网络的原因。
  • @NoamYizraeli 在写这篇文章之前已经尝试查看日志。这里什么都没有。似乎正在设置容器,但里面的应用程序运行不正常。图片 imo 有问题
  • @JakubKołacz 目前很难重现您的问题或解决问题,请调试您的问题并尽可能删除,以便我们自己体验您的问题并尝试帮助您解决修复它

标签: asp.net docker docker-compose rabbitmq


【解决方案1】:

解决办法是在dockerfile中加入这一行,配置错误。目前 dotnet sdt 没有 dotnet-ef commang:

 RUN dotnet tool install -g dotnet-ef --version 5.0

我不得不将它手动放入 dockerfile。 帮助文章的链接:

Command dotnet ef not found in .NET Core 3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-28
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多