I’m in the process of upgrading my Api project to dotnet 8 but having issues including SQL Anywhere 17 drivers, which is an upgrade from SQL Anywhere 17 in my image. In dotnet 3.1 it works fine but not so much in dotnet 8.
Unfortunately, I have no control over using SQL Anywhere as its a 3rd party system I’m integrating into.
Here is the original dockerfile for dotnet 3.1
FROM mcr.microsoft.com/dotnet/sdk:3.1 as build
WORKDIR /app
COPY . ./
RUN dotnet publish -c Release -o /out
FROM mcr.microsoft.com/dotnet/aspnet:3.1
WORKDIR /
COPY --from=jaschweder/sybase /opt/sqlanywhere16 ./opt/sqlanywhere16
RUN apt-get update && apt-get -y install unixodbc-dev
COPY ./Common/sqlanywhere-driver.template ./opt/sqlanywhere16/
RUN odbcinst -i -d -f /opt/sqlanywhere16/sqlanywhere-driver.template
ENV SQLANY16="/opt/sqlanywhere16"
ENV PATH="$SQLANY16/bin64:$SQLANY16/bin32:${PATH:-}"
ENV LD_LIBRARY_PATH="$SQLANY16/lib64:${LD_LIBRARY_PATH:-}"
WORKDIR /app
COPY --from=build /out/ .
ENTRYPOINT [ "dotnet", "Web.Api.dll" ]
So now, after lots of struggle, I need to manually download SQL Anywhere 17 and install it but even after all this, I can’t get it to work.
Here is my dotnet 8 docker file (It does look overwhelming but there are lots of validations to see where it fails)
# Stage 1: Building the .NET 8 application
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
COPY . ./
RUN dotnet publish -c Release -o /out
# Stage 2: Final runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
# Install necessary tools and ODBC drivers
RUN apt-get update &&
apt-get install -y
wget
curl
build-essential
file
tar
gzip
unixodbc
unixodbc-dev
libtool
m4
automake
autoconf
pkg-config
# Verify initial unixODBC installation
RUN echo "Verifying initial unixODBC installation:" &&
which odbcinst &&
odbcinst -j || { echo "odbcinst command failed"; exit 1; }
# Copy the unixODBC tarball to the container
COPY SQLAnywhereClient/unixODBC-2.3.11.tar.gz /tmp/unixODBC-2.3.11.tar.gz
# Manually install unixODBC
RUN cd /tmp &&
tar -xzvf unixODBC-2.3.11.tar.gz &&
cd unixODBC-2.3.11 &&
./configure &&
make &&
make install
# Verify manually installed unixODBC installation
RUN echo "Verifying manually installed unixODBC installation:" &&
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib/x86_64-linux-gnu &&
which odbcinst &&
odbcinst -j || { echo "odbcinst command failed"; exit 1; }
# Copy the SQL Anywhere 17 tarball to the container
COPY SQLAnywhereClient/sqla17_client_linux_x86x64.tar.gz /tmp/sqla17_client_linux_x86x64.tar.gz
# Inspect and extract the tarball
RUN cd /tmp &&
echo "Checking file type of the tarball:" &&
file sqla17_client_linux_x86x64.tar.gz &&
echo "Attempting to extract the tarball using tar:" &&
tar -xvf sqla17_client_linux_x86x64.tar.gz &&
echo "Checking contents of /tmp after extraction:" &&
ls -l /tmp &&
echo "Checking contents of /tmp/client17011:" &&
ls -l /tmp/client17011
# Make setup script executable and run it
RUN cd /tmp/client17011 &&
echo "Making setup script executable:" &&
chmod +x setup &&
echo "Checking if setup script is executable:" &&
ls -l setup &&
echo "Running setup script:" &&
./setup -nogui -I_accept_the_license_agreement -silent || { echo "Setup script failed"; exit 1; }
# Ensure the required libraries are in the correct place
RUN ln -sf /opt/sqlanywhere17/lib64/libdbodbc17.so /usr/lib/libdbodbc17.so &&
ln -sf /opt/sqlanywhere17/lib64/libodbc.so /usr/lib/libodbc.so.2 &&
ln -sf /opt/sqlanywhere17/lib64/libodbcinst.so /usr/lib/libodbcinst.so.2 &&
ln -sf /opt/sqlanywhere17/lib64/libodbcinst.so /usr/local/lib/libodbcinst.so.2 &&
ln -sf /opt/sqlanywhere17/lib64/libodbcinst.so /usr/lib/x86_64-linux-gnu/libodbcinst.so.2
# Set environment variables
ENV SQLANY17="/opt/sqlanywhere17"
ENV PATH="$SQLANY17/bin64:$SQLANY17/bin32:/usr/local/bin:/usr/bin:${PATH:-}"
ENV NODE_PATH="$SQLANY17/node:${NODE_PATH:-}"
ENV LD_LIBRARY_PATH="$SQLANY17/lib32:$SQLANY17/lib64:/usr/local/lib:/usr/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH:-}"
# Verify symbolic links and library paths
RUN echo "Verifying symbolic links and library paths:" &&
ls -l /usr/lib/libodbcinst.so.2 &&
ls -l /usr/local/lib/libodbcinst.so.2 &&
ls -l /usr/lib/x86_64-linux-gnu/libodbcinst.so.2 &&
ldconfig -p | grep odbcinst
# Create the ODBC driver template content directly
RUN echo "[SQL Anywhere 17]nDescription=SQL Anywhere 17 ODBC DrivernDriver=/opt/sqlanywhere17/lib64/libdbodbc17.sonSetup=/opt/sqlanywhere17/lib64/libdbodbc17.sonUsageCount=1" > /asa.driver.template
# Configure ODBC driver
RUN . /opt/sqlanywhere17/bin64/sa_config.sh &&
echo "Verifying odbcinst installation:" &&
which odbcinst &&
odbcinst -i -d -f /asa.driver.template
# Verify installation steps
RUN echo "Step 1: Checking contents of /opt/sqlanywhere17/lib64:" &&
ls -l /opt/sqlanywhere17/lib64 || echo "Directory /opt/sqlanywhere17/lib64 does not exist"
RUN echo "Step 2: Checking if libodbc.so or libodbc.so.2 exists:" &&
if [ -f /opt/sqlanywhere17/lib64/libodbc.so ]; then echo "libodbc.so found"; else echo "libodbc.so not found"; fi &&
if [ -f /opt/sqlanywhere17/lib64/libodbc.so.2 ]; then echo "libodbc.so.2 found"; else echo "libodbc.so.2 not found"; exit 1; fi
RUN echo "Step 3: Checking if libdbodbc17.so exists:" &&
if [ -f /opt/sqlanywhere17/lib64/libdbodbc17.so]; then echo "libdbodbc17.so found"; else echo "libdbodbc17.so not found"; exit 1; fi
RUN echo "Step 4: Checking odbcinst installation:" &&
which odbcinst &&
odbcinst -j
RUN echo "Step 5: Checking installed drivers:" &&
odbcinst -q -d
RUN echo "Step 6: Checking configured data sources:" &&
odbcinst -q -s
COPY --from=build /out/ .
ENTRYPOINT ["dotnet", "Web.Api.dll"]
This is the error I get and can’t seem to get away from it even when I install unixODBC
Verifying initial unixODBC installation:
odbcinst command failed