错误:“无法加载命令,可能是因为:”尝试启动 selenium docker 容器时

问题描述 投票:0回答:1

我想在 docker 中执行测试并为其创建 3 个容器:

  • chrome 节点
  • 硒中心
  • 硒.测试

前 2 个容器已成功运行,但当 selenium.test 容器尝试启动时出现错误:

2024-02-27 16:16:10 The command could not be loaded, possibly because:
2024-02-27 16:16:10   * You intended to execute a .NET application:
2024-02-27 16:16:10       The application 'BitflySelenium.dll' does not exist.
2024-02-27 16:16:10   * You intended to execute a .NET SDK command:
2024-02-27 16:16:10       No .NET SDKs were found.
2024-02-27 16:16:10 
2024-02-27 16:16:10 Download a .NET SDK:
2024-02-27 16:16:10 https://aka.ms/dotnet-download
2024-02-27 16:16:10 
2024-02-27 16:16:10 Learn about SDK resolution:
2024-02-27 16:16:10 https://aka.ms/dotnet/sdk-not-found

我尝试了在谷歌中可以找到的不同方法,但我找不到任何解决方案。

我的Dockerfile看起来像这样:

# Build stage
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
EXPOSE 80
EXPOSE 443
EXPOSE 4444

WORKDIR /app
COPY . .

RUN dotnet restore "BitflySelenium/BitflySelenium.csproj"
RUN dotnet build "BitflySelenium/BitflySelenium.csproj" -c Release

# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app .
ENTRYPOINT ["dotnet", "BitflySelenium.dll"]

我的docker-compose.yml看起来像这样:

version: '3.8'

services:
  selenium-hub:
    image: selenium/hub:4.1.2
    ports:
      - "4444:4444"

  chrome-node:
    image: selenium/node-chrome:4.1.2
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  selenium.test:
    build:
      context: .
      dockerfile: BitflySelenium/Dockerfile
    depends_on:
      - selenium-hub
    environment:
      - ASPNETCORE_ENVIRONMENT=Development

要启动容器并创建图像,请使用以下命令:

docker-compose up --build

这只是我使用的个人项目,只是为了提高我在 selenium 和 docker 方面的技能。我随机选择了“Bitfly”网站。

我将不胜感激任何提示/帮助!

docker docker-compose dockerfile
1个回答
0
投票

错误消息表明

dotnet
无法找到.dll。

我创建了一个最小的 .Net 应用程序用于测试。

├── BitflySelenium
│   ├── appsettings.Development.json
│   ├── appsettings.json
│   ├── BitflySelenium.csproj
│   ├── Controllers
│   │   └── WeatherForecastController.cs
│   ├── Dockerfile
│   ├── obj
│   │   ├── BitflySelenium.csproj.nuget.dgspec.json
│   │   ├── BitflySelenium.csproj.nuget.g.props
│   │   ├── BitflySelenium.csproj.nuget.g.targets
│   │   ├── project.assets.json
│   │   └── project.nuget.cache
│   ├── Program.cs
│   ├── Properties
│   │   └── launchSettings.json
│   └── WeatherForecast.cs
└── docker-compose.yml

我使用了您的

docker-compose.yml
并对
Dockefile
做了两个小调整,具体说明
dotnet build
的输出位置,然后在
ENTRYPOINT
中使用该路径。

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
EXPOSE 80
EXPOSE 443
EXPOSE 4444

WORKDIR /app
COPY . .

RUN dotnet restore "BitflySelenium/BitflySelenium.csproj"
# ⭐ Add the -o option here.
RUN dotnet build "BitflySelenium/BitflySelenium.csproj" -c Release -o build

FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app .
# ⭐ Specify path to .dll here!
ENTRYPOINT ["dotnet", "build/BitflySelenium.dll"]

.Net 应用程序除了运行之外不执行任何有意义的操作。通过此设置,您将不再收到报告的错误,并且可以添加所有应用程序逻辑。

© www.soinside.com 2019 - 2024. All rights reserved.