Php: Install msodbcsql, mssql-tools on php images

Created on 9 May 2017  路  6Comments  路  Source: docker-library/php

In order to user https://msdn.microsoft.com/en-us/library/hh556234(v=vs.110).aspx SQL Client streaming I would like to install the latest version of msodbcsql and tools on top of the php images but I am failing at the moment. The instructions are ubuntu 15 or 16 specific and the current compatibility problem with packages on debian:jessie as mentioned on https://github.com/docker-library/php/issues/343 in my case is with glibc being older than 2.21

What I attempted to far is to run

FROM php:fpm
MAINTAINER Diego Gullo <[email protected]>

#language-pack-en-base

RUN apt-get update && apt-get install -y \
    libmcrypt-dev libxml2-dev software-properties-common python-software-properties  apt-transport-https \ 
    && docker-php-ext-install -j$(nproc) mcrypt mbstring xml


# ubuntu 15 mssql pre-requisites
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl https://packages.microsoft.com/config/ubuntu/15.10/prod.list > /etc/apt/sources.list.d/mssql-release.list 
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools \
    && apt-get install -y unixodbc-dev

RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile \
    && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc \
    && source ~/.bashrc

I get the error on RUN apt-get update step 5

Step 5 : RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools   && apt-get install -y unixodbc-dev
 ---> Running in a4978b285e5a
Hit http://security.debian.org jessie/updates InRelease
Get:1 http://security.debian.org jessie/updates/main amd64 Packages [509 kB]
Get:2 https://packages.microsoft.com wily InRelease [2833 B]
Get:3 https://packages.microsoft.com wily/main amd64 Packages [4599 B]
Ign http://deb.debian.org jessie InRelease
Hit http://deb.debian.org jessie-updates InRelease
Hit http://deb.debian.org jessie Release.gpg
Get:4 http://deb.debian.org jessie-updates/main amd64 Packages [17.6 kB]
Hit http://deb.debian.org jessie Release
Get:5 http://deb.debian.org jessie/main amd64 Packages [9065 kB]
Fetched 9599 kB in 3s (2893 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 msodbcsql : Depends: libc6 (>= 2.21) but 2.19-18+deb8u6 is to be installed
 mssql-tools : Depends: libc6 (>= 2.21) but 2.19-18+deb8u6 is to be installed
               Depends: libstdc++6 (>= 5.2) but 4.9.2-10 is to be installed
E: Unable to correct problems, you have held broken packages.
ERROR: Service 'php7' failed to build: The command '/bin/sh -c apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools     && apt-get install -y unixodbc-dev' returned a non-zero code: 100

I asked on IRC and updating glibc manually sounds like a dirty approach, see http://stackoverflow.com/questions/10863613/how-to-upgrade-glibc-from-version-2-13-to-2-15-on-debian . Are we getting any updates on debian:jessie that will fix this problem?

Most helpful comment

@thinkspill indeed the first setup is my experiment. I have also just tried version 4.2.0 but it is not stable and they produce errors, as you can see https://github.com/Microsoft/msphpsql/issues/400

Also I think it would be great if there was a scripted approach using docker-php-ext-install sqlsrv pdo_sqlsrv. I will keep this still open just to give an update in case I can fix the problem on the current image

All 6 comments

Hey @bizmate, just a note that MS recently released a version with Jessie support:

https://github.com/Microsoft/msphpsql/releases

...and a wiki about installing support into the PHP image:

https://github.com/Microsoft/msphpsql/wiki/Install-and-configuration#docker-files

Do note that the wiki lists v4.1.8. Be sure to update that line to 4.2.0, or whatever is the latest version on the releases page.

Hope that helps!

@thinkspill indeed the first setup is my experiment. I have also just tried version 4.2.0 but it is not stable and they produce errors, as you can see https://github.com/Microsoft/msphpsql/issues/400

Also I think it would be great if there was a scripted approach using docker-php-ext-install sqlsrv pdo_sqlsrv. I will keep this still open just to give an update in case I can fix the problem on the current image

I have it running on my side.

Maybe this helps you to get started:

FROM php:7.1-fpm

# Set timezone
RUN rm /etc/localtime
RUN ln -s /usr/share/zoneinfo/Europe/Paris /etc/localtime
RUN "date"

# install ODBC driver
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev
RUN set -xe \
    && pecl install pdo_sqlsrv \
    && docker-php-ext-enable pdo_sqlsrv \
    && apt-get purge -y unixodbc-dev && apt-get autoremove -y && apt-get clean

# set locale to utf-8
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
RUN locale-gen
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'

# Here I copy my adapted odbc.ini containing the "[ODBC Driver 13 for SQL Server]" section from MS package.
COPY conf/odbc/*.ini /etc/

@discordier i dont see a major difference with https://github.com/Microsoft/msphpsql/issues/400 . The important part might be something that you omitted, could you please share the conf/odbc/*.ini files

I get permission errors in that setup, apparently thrown by not running the container as sudo (is you see the exchange of msgs there). Something in those odbc config files might be able to make a difference

Nope, it is the stock .ini file.

However, I also ran into your mentioned issue but worked around it via a hack.
Your user running the container MUST be in the docker group.
Dropping of privileges/switching of uid must be done by the container command.

Something like this might get you going (I use it to run php in server mode for local development purpose):

# execute the command with current uid and gid.
HOST_UID=`id -u`
HOST_GID=`id -g`
docker run \
  --rm \
  -v ${PWD}:/var/www \
  -it \
  -p 127.0.0.1:${PORT}:9000 \
  container-name:tag \
  /bin/sh -c "echo \"dev-user:x:${HOST_UID}:${HOST_GID}:dev user:/var/www:/bin/sh\" >> /etc/passwd && \
  su -l dev-user -s /bin/sh -c \"/usr/local/bin/php -S0.0.0.0:9000 -t /var/www/web\""

The hack is, to add an user in the container on the fly with the "outside" uid and gid. The container startup is not affected (as the "outside" user is member of the "docker" group on the host system).

Given that this appears to have reasonable solutions and isn't actually an issue with this image (but rather a general question about how to install some external Microsoft tools in a Debian-based image), I'm going to close.

In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow. Thanks!

Was this page helpful?
0 / 5 - 0 ratings