Adithya Sai
Adithya Sai

Reputation: 1740

Unable to load shared library 'libldap-2.4.so.2' or one of its dependencies

Team,

I am getting the following error when trying to run on docker. its working fine on windows machine-

Unable to load shared library 'libldap-2.4.so.2' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibldap-2.4.so.2: cannot open shared object file: No such file or directory

i am using the System.DirectoryServices.Protocols namespace for LdapConnection. have tried to install libldap in my docker image. in the following 3 ways but none of them worked.

RUN apt-get update && apt-get install libldap-2.4-2


RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libldap-2.4-2 \
    && rm -rf /var/lib/apt/lists/*

RUN apk add libldap

Here is my docker file

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libldap-2.4-2 \
    && rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY ["Ldaptest1/Ldaptest1.csproj", "Ldaptest1/"]
RUN dotnet restore "Ldaptest1/Ldaptest1.csproj"
COPY . .
WORKDIR "/src/Ldaptest1"
RUN dotnet build "Ldaptest1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Ldaptest1.csproj" -c Release -o /app/publish

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

i am currently using .NET 6 and it is breaking in the following line when initializing LdapConnection -

var connection = new LdapConnection(ldapDomain)

i have gone through this - https://github.com/dotnet/dotnet-docker/issues/1946. but that did not help.

thanks in advance

Upvotes: 9

Views: 14630

Answers (1)

They_Call_Me_Joe
They_Call_Me_Joe

Reputation: 204

Move your installations commands after your last FROM and that should fix it.

I had to do this for a .NET Core 5 image and it worked.

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Ldaptest1/Ldaptest1.csproj", "Ldaptest1/"]
RUN dotnet restore "Ldaptest1/Ldaptest1.csproj"
COPY . .
WORKDIR "/src/Ldaptest1"
RUN dotnet build "Ldaptest1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Ldaptest1.csproj" -c Release -o /app/publish

FROM base AS final
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libldap-2.4-2 \
    && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Ldaptest1.dll"]

Upvotes: 6

Related Questions