0

I'm trying to move legacy project to docker which is using msodbcsql with pdo_odbc drivers to connect to SQL Server database.

My 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

During installation I don't receive any errors and when trying to connect to SQL Server I receive following error:

"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"
Deeeic
  • 11
  • 3

1 Answers1

0

Try this code to install pdo_sqlsrv and msodbcsql on your docker:

# 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;