I am trying to integrate the C++ connector for MariaDB into a Dockerfile. My Dockerfile looks like this:
# syntax=docker/dockerfile:1
FROM alpine:3.16 AS base
RUN apk update && apk add \
libstdc++ \
mariadb-connector-c
FROM base AS builder
RUN apk update && apk add \
alpine-sdk \
cmake \
git \
curl \
musl-dev \
openssl-dev; \
cd /; \
git clone https://github.com/MariaDB-Corporation/mariadb-connector-cpp.git; \
cd mariadb-connector-cpp; \
mkdir build; \
cd build; \
cmake ../ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONC_WITH_UNIT_TESTS=Off -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_SSL=OPENSSL; \
cmake --build . --config RelWithDebInfo; \
make install
COPY ./myapp /usr/src/myapp
RUN cd /usr/src/myapp; \
make; make install
FROM base AS runtime
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /usr/local/lib /usr/local/lib
// define entrypoints, etc.
I have successfully used Dockerfiles like this before with other self-built libraries. All these other shared libraries installed themselves into /usr/local/lib/libexample.so
and were found without issues when running the application. However, the MariaDB connector creates a subdirectory and puts its shared libraries there, e.g. /usr/local/lib/mariadb/libmariadbcpp.so
.
Subsequently, my application cannot find the shared object during runtime. I am not very experienced using cmake and I wonder if there is an elegant way to make my application find the libraries by modifying the install path? I could copy the files to the parent directory, but there must be a better way.