use ENV variable in EntryPoint for Distroless image #5844
-
Hi All I have 2 different applications (web apps) and 1 common Dockerfile through which i am building the apps and containerize it. So far i was using full fledged images (debian); where in i was passing the exe name into the entrypoint as environment variable. Now i was playing with distroless and its great. It offers lot size reduction. So i was doing the same and hit a road block. I am unable to pass the environment variable to the entry point vector as shown:
i tried changing ENTRYPOINT as ENTRYPOINT ["./${CSPROJFILENAME}"]; but no luck. Please help; what could be the alternative approach if above is not supported? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi @ZenwalkerD. I tried to use your Dockerfile as-is to build a test project and found a few issues with it:
The Dockerfile was able to build after changing those things in the first layer: - FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
+ FROM mcr.microsoft.com/dotnet/sdk:8.0-noble AS build
SHELL ["/bin/bash", "-c"]
ARG csprojFileName
- COPY . /home/src
+ WORKDIR /home/src
+ COPY . .
- RUN dotnet publish "$csprojFileName.csproj"
+ RUN dotnet publish "$csprojFileName.csproj" -o /home/src/app/publish
... However, using the environment variable in the ENTRYPOINT instruction still won't work, so the Dockerfile won't run. Environment variable expansion is handled by the shell. Since the exec form for ENTRYPOINT instructions doesn't use the shell, this is the expected behavior. Distroless images cannot expand that environment variable at runtime since they don't have a shell - so you'll need to specify the exact executable name in the ENTRYPOINT instruction. You can see moby/moby#4783 for more info. One other option could be to rename the executable to something known in the build stage before it is copied to the final image. I should note that there's nothing wrong with using separate Dockerfiles for separate apps - in fact I would expect it. As apps are developed over time, requirements and dependencies change, and they may necessitate different Dockerfiles anyways. Finally, consider taking a look at our Ubuntu Chiseled ASP.NET app sample Dockerfile for inspiration. You can easily upgrade it to Noble by replacing |
Beta Was this translation helpful? Give feedback.
-
Have you considered using |
Beta Was this translation helpful? Give feedback.
Thank you. I learned something new. Very nice to have in build support!