Home > Software engineering >  Using Entrypoint with arguments to decide which .dll to run
Using Entrypoint with arguments to decide which .dll to run

Time:02-25

I am experimenting with Docker and using arguments to decide what code in the image should start.

I have these two entrypoints which both work if run by themselves.

ENTRYPOINT ["dotnet", "MultiStart.API.dll"]
ENTRYPOINT ["dotnet", "MultiStart.Worker1.dll"]

I would like to decide which one is run by using arguments when i call docker run

I've tried several things along the lines of

CMD ["dotnet", $start]
ENTRYPOINT ./dotnet $start
ENTRYPOINT ["dotnet", $start]
ENTRYPOINT ["dotnet" $start]

and then calling it using something like this.

docker run -d -p 8080:80 -e start=MultiStart.API.dll --name multi multistart

But no matter what I do I end up with this error (or some variant there of):

/bin/sh: 1: ./dotnet: not found

Any suggestions as to how this can be achieved?


Ill include the entire Dockerfile that will start one of the two processes for clarity.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["src", "src"]
COPY ["*.sln", ""]

RUN dotnet restore "src/MultiStart.API/MultiStart.API.csproj"
RUN dotnet restore "src/MultiStart.Worker1/MultiStart.Worker1.csproj"
COPY . .
WORKDIR "/src/src"
RUN dotnet build "MultiStart.API/MultiStart.API.csproj" -c Release -o /app/build
RUN dotnet build "MultiStart.Worker1/MultiStart.Worker1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "MultiStart.API/MultiStart.API.csproj" -c Release -o /app/publish
RUN dotnet publish "MultiStart.Worker1/MultiStart.Worker1.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

# both of these work by themselves.
#ENTRYPOINT ["dotnet", "MultiStart.API.dll"]  
ENTRYPOINT ["dotnet", "MultiStart.Worker1.dll"]

CodePudding user response:

docker run cannot pass variable like that, after all, docker file is not bash script. The simplist way is

dockerfile

ENTRYPOINT ["command"]

docker run

docker run imagename argument list

If you want to declare variables in docker file, you can use ARG or ENV.

  • Related