Boas Enkler
Boas Enkler

Reputation: 12557

Connecting to MongoDb atlas fails when using alpine Docker images

I've a .net / c# aspnet core application which connects to a MongoDb Atlas Cloud database. When running localy every thing works fine.

Now i put the application inside a alpine docker image the application the connection fails. I got some various exceptions pointing out that the authentication doesn't work.

Here my DockerFile which builds and runs the application

FROM microsoft/dotnet:2.1-sdk-alpine AS builder
WORKDIR /
COPY . .
RUN dotnet publish Api/Api.csproj -o /dockerout/ -c Release

FROM microsoft/dotnet:2.1.3-aspnetcore-runtime-alpine
WORKDIR /app
EXPOSE 80 5000

RUN apk update

COPY --from=builder /dockerout .

ENTRYPOINT ["dotnet", "Api.dll"]

Upvotes: 0

Views: 727

Answers (1)

Boas Enkler
Boas Enkler

Reputation: 12557

After a lot of research I found an Issue pointing me to the root cause: https://github.com/dotnet/corefx/issues/9608#issuecomment-401370142

Because it took me a lot of time I'll answer my own question hoping someone is saving the time.

There two possible solutions are a) don't use a alpine image b) update the openssl package when building the image by adding open ssl like this apk add --no-cache openssl

Full DockerFile that solved it for me:

FROM microsoft/dotnet:2.1-sdk-alpine AS builder
WORKDIR /
COPY . .
RUN dotnet publish Api/Api.csproj -o /dockerout/ -c Release

FROM microsoft/dotnet:2.1.3-aspnetcore-runtime-alpine
WORKDIR /app
EXPOSE 80 5000

RUN apk update && apk add --no-cache openssl

COPY --from=builder /dockerout .

ENTRYPOINT ["dotnet", "Api.dll"]

Upvotes: 2

Related Questions