dockerdocker-composedockerfile

Error: " The command could not be loaded, possibly because:" while trying to start a selenium docker container


I want to execute my tests in docker and created 3 containers for it:

The first 2 container are running successfully, but im getting an error when the selenium.test container tries to start:

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

I tried different approaches that i could find in google but im not able to find any solution.

My Dockerfile looks like this:

# 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"]

My docker-compose.yml looks like this:

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

To start the container and creation of the images im using this command:

docker-compose up --build

This is just a personal project i use, just to improve my skills in selenium and docker. I chose the "Bitfly" website randomly.

I would appreciate any hints/help!


Solution

  • The error message indicates that dotnet is unable to find the .dll.

    I created a minimal .Net application for testing.

    ├── 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
    

    I used your docker-compose.yml and made two minor tweaks to the Dockefile, being specific about the location of the output from dotnet build and then using that path in 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"]
    

    The .Net application doesn't do anything meaningful except run. With this setup you'll no longer get the errors you reported and you can add all of your application logic.

    enter image description here