Image ubuntu/dotnet-deps:7.0_edge with my application compiled as self-contained for a specific architecture (amd64/arm64).
Example code:
Runtime image:
FROM --platform=$BUILDPLATFORM registry.***.com/developer.dotnet:base as base
ARG TARGETARCH
ARG BUILDPLATFORM
RUN echo "Target: $TARGETARCH"
RUN echo "Build: $BUILDPLATFORM"
FROM --platform=$BUILDPLATFORM ubuntu/dotnet-deps:${version}_edge
ARG TARGETARCH
ARG BUILDPLATFORM
COPY --from=base /usr/lib /usr/lib
Application image:
ARG commit
FROM --platform=$BUILDPLATFORM registry.***.com/build:backend-${commit} AS build-env
ARG project
ARG TARGETARCH
ARG BUILDPLATFORM
ENV PROJECT=${project}
RUN echo "Target: $TARGETARCH"
RUN echo "Build: $BUILDPLATFORM"
RUN dotnet publish src/${project}/${project}.csproj -c Release -o out/ --self-contained true -a $TARGETARCH
RUN cd out && ln -s $PROJECT application
# Build runtime image
FROM registry.***.com/developer.dotnet:7.0
# Prepare Application
WORKDIR /app
COPY --from=build-env /home/app/out .
USER app
# Prepare Entry
ENTRYPOINT ["/app/application"]
Output:
The type initializer for 'OpenCvSharp.Internal.NativeMethods' threw an exception.
System.TypeInitializationException: The type initializer for 'OpenCvSharp.Internal.NativeMethods' threw an exception.
---> System.DllNotFoundException: Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
/app/OpenCvSharpExtern.so: cannot open shared object file: No such file or directory
libopencv_stitching.so.407: cannot open shared object file: No such file or directory
libOpenCvSharpExtern.so: cannot open shared object file: No such file or directory
/app/OpenCvSharpExtern: cannot open shared object file: No such file or directory
/app/libOpenCvSharpExtern: cannot open shared object file: No such file or directory
What did you intend to be?
I am now debugging with LD_DEBUG=libs to figure out where to put the files so the self-contained application finds the libs but I was wondering if you didn't already have a dockerfile for this prepared?
Summary of your issue
I am trying to compile OpenCV and OpenCVSharp like the examples found here https://github.com/shimat/opencvsharp/tree/master/docker and at the very end copy it from builder to https://hub.docker.com/r/ubuntu/dotnet-deps image, so I can run my self-contained application in a non-root mode without any system/tooling unnecessary garbage.
Environment
Image
ubuntu/dotnet-deps:7.0_edge
with my application compiled as self-contained for a specific architecture (amd64/arm64).Example code:
Runtime image:
Application image:
Output:
What did you intend to be?
I am now debugging with
LD_DEBUG=libs
to figure out where to put the files so the self-contained application finds the libs but I was wondering if you didn't already have a dockerfile for this prepared?