Home > Enterprise >  /bin/sh: [./Filename]: not found
/bin/sh: [./Filename]: not found

Time:07-02

FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine as base
WORKDIR /app

RUN apk add --no-cache ca-certificates icu-libs

RUN apk add --no-cache tzdata
RUN apk add --no-cache bash

ENV TZ=America/Chicago
#This will update the image to avoid security issues.
RUN apk update
RUN apk upgrade
RUN apk add bash
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
WORKDIR /src

COPY ["Filename/Filename.csproj", "Filename/"]


RUN dotnet restore "Filename/Filename.csproj" --configfile NuGet.Config 
COPY . .
WORKDIR "/src/Filename"
RUN dotnet build "Filename.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Filename.csproj" -c Release -o /app/publish  --runtime alpine-x64 --self-contained true /p:PublishTrimmed=true /p:PublishSingleFile=true

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
#ENTRYPOINT ["dotnet", "Filename.dll"]
ENTRYPOINT [./"Filename"]

I have a console application with Dotnet 6.0. My dockerfile script built successfully however, it failed at runtime when deploying to the server with Error : /bin/sh: [./Filename]: not found

my image ran fine when it's dotnetcore 3.1 and with script runtime-deps:3.1-alpine AS base. So why does it require /bin/sh: when it's in dotnet 6.0. How do you fix this issue? Any help is greatly appreciated.

CodePudding user response:

Change the entrypoint at the end of your dockerfile:

ENTRYPOINT ["./Filename"]

CodePudding user response:

Updated your dockerfile you can use it, It will resolve the issue..!!!

FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine as base
WORKDIR /app

RUN apk add --no-cache ca-certificates icu-libs

RUN apk add --no-cache tzdata
RUN apk add --no-cache bash

ENV TZ=America/Chicago
#This will update the image to avoid security issues.
RUN apk update
RUN apk upgrade
RUN apk add bash
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
WORKDIR /src

COPY ["Filename/Filename.csproj", "Filename/"]


RUN dotnet restore "Filename/Filename.csproj" --configfile NuGet.Config 
COPY . .
WORKDIR "/src/Filename"
RUN dotnet build "Filename.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Filename.csproj" -c Release -o /app/publish  --runtime alpine-x64 --self-contained true /p:PublishTrimmed=true /p:PublishSingleFile=true

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
EXPOSE portnumber
ENV ASPNETCORE_URLS http://*:portnumber
ENTRYPOINT ["dotnet", "Filename.dll"]
  • Related