I have an net6 app running in docker in Release mode. Im trying to setup the Dockerfile in a way I can add a parameter to set if ill run in Debug or Release mode, but its not working.
This is my attempt:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS base
WORKDIR /app
ARG APP_PORT=80
ARG MODE="Release"
EXPOSE ${APP_PORT}
ENV ASPNETCORE_URLS=http://*:${APP_PORT}
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["./Gateway.csproj", "app/"]
RUN dotnet restore "app/Gateway.csproj"
COPY . .
RUN dotnet build "/src/Gateway.csproj" -c ${MODE} -o /app/build
FROM build AS publish
RUN dotnet publish "/src/Gateway.csproj" -c ${MODE} -o /app/publish
FROM base AS runtime
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Gateway.dll"]
Error im getting:
> [build 6/6] RUN 'dotnet build "/src/Gateway.csproj" -c ${MODE} -o /app/build':
#12 0.176 /bin/sh: 1: dotnet build "/src/Gateway.csproj" -c ${MODE} -o /app/build: not found
------
executor failed running [/bin/sh -c 'dotnet build "/src/Gateway.csproj" -c ${MODE} -o /app/build']: exit code: 127
ERROR: Service 'gateway' failed to build : Build failed
Tried searching all I could on this could not find how to do this.
2
Answers
Remove the { and } and it works:
The point is , you should declare ARG for every stage. For more information , you can see this link .
The correct dockerfile is