skip to Main Content

I am getting this error when I try to connect to the sqlserver db:

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension 
requires the Microsoft ODBC Driver for SQL Server. Access the following URL to download the ODBC 
Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 [message] => This 
extension requires the Microsoft ODBC Driver for SQL Server. Access the following URL to download the 
ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 ) )

My Dockerfile below:

FROM microsoft/mssql-tools as mssql
FROM php:7.2-fpm-alpine

COPY --from=mssql /opt/microsoft/ /opt/microsoft/
COPY --from=mssql /opt/mssql-tools/ /opt/mssql-tools/
COPY --from=mssql /usr/lib/libmsodbcsql-13.so /usr/lib/libmsodbcsql-13.so

RUN apk update 
&& apk add  --no-cache git mysql-client curl libmcrypt libmcrypt-dev openssh-client icu-dev 
unixodbc-dev 
libxml2-dev freetype-dev libpng-dev libjpeg-turbo-dev g++ make autoconf 
&& docker-php-source extract 
&& pecl install xdebug redis 
&& docker-php-ext-enable xdebug redis 
&& docker-php-source delete 
&& docker-php-ext-install pdo_mysql soap intl zip 
&& pecl install 
    sqlsrv 
    pdo_sqlsrv 
&& docker-php-ext-enable --ini-name 30-sqlsrv.ini sqlsrv 
&& docker-php-ext-enable --ini-name 35-pdo_sqlsrv.ini pdo_sqlsrv 
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 
&& echo "xdebug.remote_port=10000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 
&& echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 
&& echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 
#&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 
&& rm -rf /tmp/*

CMD ["php-fpm", "-F"]

WORKDIR /var/www/cssp

EXPOSE 9000

It seems there is a problem with the installation of the driver
Has anyone tried this before? Please share. Thank you.

2

Answers


  1. Try with below DockerFile

    FROM microsoft/mssql-tools as mssql
    FROM php:7.2-fpm-alpine
    
    COPY --from=mssql /opt/microsoft/ /opt/microsoft/
    COPY --from=mssql /opt/mssql-tools/ /opt/mssql-tools/
    COPY --from=mssql /usr/lib/libmsodbcsql-13.so /usr/lib/libmsodbcsql-13.so
    
    # Install language pack
    ENV MUSL_LOCALE_DEPS cmake make musl-dev gcc gettext-dev libintl
    ENV MUSL_LOCPATH /usr/share/i18n/locales/musl
    
    RUN apk add --no-cache 
        $MUSL_LOCALE_DEPS 
        && wget https://gitlab.com/rilian-la-te/musl-locales/-/archive/master/musl-locales-master.zip 
        && unzip musl-locales-master.zip 
          && cd musl-locales-master 
          && cmake -DLOCALE_PROFILE=OFF -D CMAKE_INSTALL_PREFIX:PATH=/usr . && make && make install 
          && cd .. && rm -r musl-locales-master
    
    # --- not show here---
    
    # mssql odbc for dabase connection
    RUN curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.5.2.1-1_amd64.apk
    RUN curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_17.5.2.1-1_amd64.apk
    RUN apk add --allow-untrusted msodbcsql17_17.5.2.1-1_amd64.apk
    RUN apk add --allow-untrusted mssql-tools_17.5.2.1-1_amd64.apk
    
    RUN set -xe 
        && apk add --no-cache --virtual .persistent-deps freetds unixodbc 
        && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS unixodbc-dev freetds-dev 
        && docker-php-source extract 
        && docker-php-ext-install pdo_dblib 
        && pecl install sqlsrv pdo_sqlsrv 
        && docker-php-ext-enable --ini-name 30-sqlsrv.ini sqlsrv 
        && docker-php-ext-enable --ini-name 35-pdo_sqlsrv.ini pdo_sqlsrv 
        && docker-php-source delete 
        && apk del .build-deps
    
    
    Login or Signup to reply.
  2. If you’re stuck with php 7.1 like I do now, here is the updated Dockerfile:

    FROM mcr.microsoft.com/mssql-tools as mssql
    FROM FROM php:7.1-fpm-alpine
    
    ENV MUSL_LOCALE_DEPS cmake make musl-dev gcc gettext-dev libintl
    ENV MUSL_LOCPATH /usr/share/i18n/locales/musl
    
    COPY --from=mssql /opt/microsoft/ /opt/microsoft/
    COPY --from=mssql /opt/mssql-tools/ /opt/mssql-tools/
    COPY --from=mssql /usr/lib/libmsodbcsql-13.so /usr/lib/libmsodbcsql-13.so
    
    RUN apk add --no-cache 
        $MUSL_LOCALE_DEPS 
        && wget https://gitlab.com/rilian-la-te/musl-locales/-/archive/master/musl-locales-master.zip 
        && unzip musl-locales-master.zip 
          && cd musl-locales-master 
          && cmake -DLOCALE_PROFILE=OFF -D CMAKE_INSTALL_PREFIX:PATH=/usr . && make && make install 
          && cd .. && rm -r musl-locales-master
    
    # mssql odbc for dabase connection
    RUN curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.5.2.1-1_amd64.apk
    RUN curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_17.5.2.1-1_amd64.apk
    RUN apk add --allow-untrusted msodbcsql17_17.5.2.1-1_amd64.apk
    RUN apk add --allow-untrusted mssql-tools_17.5.2.1-1_amd64.apk
    
    RUN set -xe 
        && apk add --no-cache --virtual .persistent-deps freetds unixodbc 
        && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS unixodbc-dev freetds-dev 
        && docker-php-source extract 
        && docker-php-ext-install pdo_dblib 
        && pecl install sqlsrv-5.6.1 pdo_sqlsrv-5.6.1 
        && docker-php-ext-enable --ini-name 30-sqlsrv.ini sqlsrv 
        && docker-php-ext-enable --ini-name 35-pdo_sqlsrv.ini pdo_sqlsrv 
        && docker-php-source delete 
        && apk del .build-deps
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search