How to fix error failed to solve: process "/bin/sh -c apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib tzdata" did not complete successfully: exit code: 127

We have this Dockerfile on which we are trying to prepare our dotnet applications. We have an issue where we face this error

ERROR: failed to solve: process "/bin/sh -c apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib tzdata" did not complete successfully: exit code: 127

This is our Dockerfile:


FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ENV NUGET_PACKAGES=/src/
WORKDIR /src

COPY ["WebApi/WebApi.csproj", "WebApi/"]
COPY ["Application/Application.csproj", "Application/"]
COPY ["Domain/Domain.csproj", "Domain/"]
COPY ["ExternalService/ExternalService.csproj", "ExternalService/"]
COPY ["Persistence/Persistence.csproj", "Persistence/"]
COPY ["NuGet.Config", "./"]

RUN dotnet nuget disable source nuget.org
RUN dotnet restore "WebApi/WebApi.csproj"
COPY . .
WORKDIR "/src/WebApi"
RUN dotnet build "WebApi.csproj" -c Release -o /app/build

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS base
WORKDIR /app
ENV DOTNET_RUNNING_IN_CONTAINER=true
RUN apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib tzdata
ENV ID=Asia/Jakarta
RUN cp /usr/share/zoneinfo/Asia/Jakarta /etc/localtime
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
EXPOSE 8080

FROM build AS publish
RUN dotnet publish "WebApi.csproj" -c Release -o /app/publish \
   -r alpine-x64 \
   -p:PublishTrimmed=true
WORKDIR /src

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["./WebApi", "--urls", "http://0.0.0.0:8080"]

Stack Traces :

docker: invalid reference format: repository name (Dockerfile) must be lowercase

Run 'docker run --help' for more information
[admin-dev@T13676 ahmsvhrmes042-cnp]$ sudo docker build -t ahmsvhrmes042-cnp .
[+] Building 0.9s (15/24)                                                                                                                                                                                     docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                                                    0.0s
 => => transferring dockerfile: 1.18kB                                                                                                                                                                                  0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:8.0                                                                                                                                                       0.2s
 => [internal] load .dockerignore                                                                                                                                                                                       0.0s
 => => transferring context: 358B                                                                                                                                                                                       0.0s
 => [build  1/13] FROM mcr.microsoft.com/dotnet/sdk:8.0@sha256:483d6f3faa583c93d522c4ca9ee54e08e535cb112dceb252b2fbb7ef94839cc8                                                                                         0.0s
 => CACHED [base 2/4] WORKDIR /app                                                                                                                                                                                      0.0s
 => ERROR [base 3/4] RUN apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib tzdata                                                                                                           0.5s
 => [internal] load build context                                                                                                                                                                                       0.0s
 => => transferring context: 4.30kB                                                                                                                                                                                     0.0s
 => CACHED [build  2/13] WORKDIR /src                                                                                                                                                                                   0.0s
 => CACHED [build  3/13] COPY [WebApi/WebApi.csproj, WebApi/]                                                                                                                                                           0.0s
 => CACHED [build  4/13] COPY [Application/Application.csproj, Application/]                                                                                                                                            0.0s
 => CACHED [build  5/13] COPY [Domain/Domain.csproj, Domain/]                                                                                                                                                           0.0s
 => CACHED [build  6/13] COPY [ExternalService/ExternalService.csproj, ExternalService/]                                                                                                                                0.0s
 => CACHED [build  7/13] COPY [Persistence/Persistence.csproj, Persistence/]                                                                                                                                            0.0s
 => CACHED [build  8/13] COPY [NuGet.Config, ./]                                                                                                                                                                        0.0s
 => CANCELED [build  9/13] RUN dotnet nuget disable source nuget.org                                                                                                                                                    0.7s
------
 > [base 3/4] RUN apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib tzdata:
0.447 /bin/sh: 1: apk: not found
------
Dockerfile:21
--------------------
  19 |     WORKDIR /app
  20 |     ENV DOTNET_RUNNING_IN_CONTAINER=true
  21 | >>> RUN apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib tzdata
  22 |     ENV ID=Asia/Jakarta
  23 |     RUN cp /usr/share/zoneinfo/Asia/Jakarta /etc/localtime
--------------------
ERROR: failed to solve: process "/bin/sh -c apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib tzdata" did not complete successfully: exit code: 127

Cheers

It seems the image is Debian Linux based, but you try to run apk, an Alpine Linux command.

1 Like

This confirms what @bluepuma77 wrote:

me@host ~ $ sudo docker run -ti --rm mcr.microsoft.com/dotnet/sdk:8.0 cat /etc/os-release
Unable to find image 'mcr.microsoft.com/dotnet/sdk:8.0' locally
8.0: Pulling from dotnet/sdk
7cf63256a31a: Pull complete
c0061e74b3e3: Pull complete
b4027bb0a9ca: Pull complete
d43efb33ab76: Pull complete
457ab9651207: Pull complete
8d92f14b195f: Pull complete
738d5a9f7975: Pull complete
41dfabb4c1e9: Pull complete
daf821adade2: Pull complete
Digest: sha256:483d6f3faa583c93d522c4ca9ee54e08e535cb112dceb252b2fbb7ef94839cc8
Status: Downloaded newer image for mcr.microsoft.com/dotnet/sdk:8.0
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

You either need to replace the apk commands with their apt counterparts (please look up the exact commands!), or actually use the alpine based mcr.microsoft.com/dotnet/sdk:8.0-alpine base image:

me@host ~ $ sudo docker run -ti --rm mcr.microsoft.com/dotnet/sdk:8.0-alpine cat /etc/os-release
Unable to find image 'mcr.microsoft.com/dotnet/sdk:8.0-alpine' locally
8.0-alpine: Pulling from dotnet/sdk
f18232174bc9: Already exists
2e6d13c80cd2: Pull complete
a8218a775405: Pull complete
79004341ba3f: Pull complete
b2ab935254a3: Pull complete
06f9f56c8745: Pull complete
c8f25de41b68: Pull complete
5f498fc6f882: Pull complete
Digest: sha256:1659a7a350b7847f6afc84df1409c6b80fd08e7decf51f5c365303b0d625f13b
Status: Downloaded newer image for mcr.microsoft.com/dotnet/sdk:8.0-alpine
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.21.3
PRETTY_NAME="Alpine Linux v3.21"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"

Thanks guys, i’ve fixed it with @bluepuma77 recommendation. I used mcr.microsoft.com/dotnet/sdk:8.0-alpine and it works.

1 Like