We want to use a single Dockerfile
for a few different projects.
The projects structure is the same and the only different as far as the Dockerfile concerns is the entrypoint dll
.
Here is how one of those Dockerfile
s looks like:
FROM mcr.microsoft.com/dotnet/runtime:5.0-alpine3.13-amd64
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "dllName.dll"]
I thought about something like that:
FROM mcr.microsoft.com/dotnet/runtime:5.0-alpine3.13-amd64
ARG DLL_NAME
RUN echo "Building for $DLL_NAME"
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", $DLL_NAME]
And build it with: --build-arg "DLL_NAME=dllName.dll"
However, the ENTRYPOINT ["dotnet", $DLL_NAME]
command doesn't seem to go through when running the image:
/bin/sh: [dotnet,: not found
CodePudding user response:
The RUN
instruction expects variables from environment.
Please try changing
FROM mcr.microsoft.com/dotnet/runtime:5.0-alpine3.13-amd64
ARG DLL_NAME
RUN echo "Building for $DLL_NAME"
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", $DLL_NAME]
into
FROM mcr.microsoft.com/dotnet/runtime:5.0-alpine3.13-amd64
ARG DLL_NAME
ENV DLL_NAME=$DLL_NAME
RUN echo "Building for $DLL_NAME"
WORKDIR /app
COPY . .
ENTRYPOINT /bin/sh dotnet $DLL_NAME
CodePudding user response:
You can dynamically specify the command to run when you launch a container. This gets appended to the ENTRYPOINT
; but, a Dockerfile ENTRYPOINT
isn't required. If in your Dockerfile you change ENTRYPOINT
to CMD
FROM mcr.microsoft.com/dotnet/runtime:5.0-alpine3.13-amd64
WORKDIR /app
COPY . .
CMD ["dotnet", "dllName.dll"] # <-- not ENTRYPOINT
then when you launch the container you can easily override it, without rebuilding anything
docker run ... my-image \
dotnet otherDll.dll