You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Core 3.1升级.NET 8时SQL Anywhere 17驱动Docker部署问题

.NET 8 Docker环境下安装SQL Anywhere 17驱动时odbcinst命令执行失败

将API项目从.NET Core 3.1升级至.NET 8,因需对接第三方系统,必须使用SQL Anywhere 17驱动。原.NET Core 3.1版本的Dockerfile可正常运行,但升级到.NET 8后,手动安装SQL Anywhere 17驱动时遇到问题——即便安装了unixODBC,仍无法解决「odbcinst命令失败」的报错。

原.NET Core 3.1 Dockerfile

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" ]

当前.NET 8 Dockerfile(含验证步骤)

# 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]
Description=SQL Anywhere 17 ODBC Driver
Driver=/opt/sqlanywhere17/lib64/libdbodbc17.so
Setup=/opt/sqlanywhere17/lib64/libdbodbc17.so
UsageCount=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"]

报错信息

Verifying initial unixODBC installation:

odbcinst command failed

已尝试的手动安装步骤

# Manually download and install SQL Anywhere
RUN wget https://www.sqlanywhere.info/download/2022/sqla17_client_linux_x86x64.tar.gz && \
    tar -xzvf sqla17_client_linux_x86x64.tar.gz && \
    cd sqla17_client_linux_x86x64 && \
    ./configure && \
    make && \
    make install

# Manually download and install unixODBC
RUN wget http://www.unixodbc.org/unixODBC-2.3.11.tar.gz && \
    tar -xzvf unixODBC-2.3.11.tar.gz && \
    cd unixODBC-2.3.11 && \
    ./configure && \
    make && \
    make install

内容的提问来源于stack exchange,提问作者Gericke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 16:32:03