skip to Main Content

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


  1. Remove the { and } and it works:

    RUN dotnet build "/src/Gateway.csproj" -c $MODE -o /app/build
    
    Login or Signup to reply.
  2. The point is , you should declare ARG for every stage. For more information , you can see this link .

    The correct dockerfile is

    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
    #**********************************
    ARG MODE="Release" # I added this**
    #**********************************
    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
    #**********************************
    ARG MODE="Release" # I added this**
    #**********************************
    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"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search