Laradock安装msodbcsql

时间:2018-08-21 19:10:12

标签: php sql-server docker laradock

我正在尝试将旧项目移至docker,该项目使用msodbcsql和pdo_odbc驱动程序来连接到SQL Server数据库。

我的dockerfile:

#install freetds
RUN apt-get update && \
    apt-get install -y gnupg2 && \
    apt-get install -y apt-transport-https && \
    curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
    curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
    apt-get update

RUN ACCEPT_EULA=Y \
    apt-get install -y unixodbc unixodbc-dev libgss3 odbcinst msodbcsql locales freetds-dev && \
    echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
    locale-gen && \
    rm -rf /var/lib/apt/lists/*

RUN apt-get update && \
    apt-get install -y git freetds-dev zlib1g-dev && \
    rm -rf /var/lib/apt/lists/*

#pdo_odbc drivers
RUN apt-get install -y \
    unixODBC-dev \
    && docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr \
    && docker-php-ext-install pdo_odbc \
    && docker-php-ext-enable pdo_odbc

#Config files from current debian server
COPY ./freetds.conf /etc/freetds/freetds.conf
COPY ./odbc.ini /etc/odbc.ini
COPY ./odbcinst.ini /etc/odbcinst.ini

在安装过程中,我没有收到任何错误,并且在尝试连接到SQL Server时收到以下错误:

"error":"SQLSTATE[01000] SQLConnect: 0 [unixODBC][Driver Manager]Can't open lib '\/opt\/microsoft\/msodbcsql\/lib64\/libmsodbcsql-11.0.so.2270.0' : file not found"

1 个答案:

答案 0 :(得分:0)

尝试以下代码在docker上安装pdo_sqlsrv和msodbcsql:

# Install selected extensions and other stuff
RUN apt-get update \
    && apt-get -y --no-install-recommends install wget php-memcached php7.2-mysql php-redis php7.2-bz2 php7.2-gd php-imagick php7.2-odbc php7.2-xmlrpc php-yaml \
    && apt-get -y install unixodbc-dev; apt-get -y install php-pear; apt-get install -y php7.2-dev;\
    pecl install sqlsrv pdo_sqlsrv;

# Install ODBC
RUN wget https://packages.microsoft.com/ubuntu/17.04/prod/pool/main/m/msodbcsql/msodbcsql_13.1.9.1-1_amd64.deb;
RUN apt-get -y install unixodbc libcurl3;
RUN ACCEPT_EULA=Y \
    dpkg -i msodbcsql_13.1.9.1-1_amd64.deb;
RUN apt-get install -y locales \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen\
    && locale-gen;