Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add this driver to the alpine linux php docker image #300

Open
zippy1981 opened this issue Feb 23, 2017 · 59 comments
Open

Add this driver to the alpine linux php docker image #300

zippy1981 opened this issue Feb 23, 2017 · 59 comments

Comments

@zippy1981
Copy link

Alpine linux uses a smaller libc than ubuntu and redhat and produces really small docker images. There are official php docker images on docker hub that use this. One installs an extension on them via the command docker-php-ext-install this compiles the extension from source and setups up an INI file for it.

I have not determined if any of the following tasks are already done:

  1. Compile this driver on alpine linux. If this works can someone at MSFT setup travis CI to do this?
  2. Get whoever maintains the alpine linux php docker images on board with this
  3. Create a pull request so docker-php-ext-install will pull the driver.
@mimetnet
Copy link

AFAIK, the ODBC driver from Microsoft is not compatible with Alpine because of musl's libc.

@meet-bhagdev
Copy link
Contributor

@zippy1981 We can get the PHP Driver to compile on Alpine Linux but the ODBC Driver as @mimetnet mentioned, is not compatible with Alpine. We do have a docker image that you can use for now: https://hub.docker.com/r/lbosqmsft/php-mssql/. We are looking into supporting additional distros (alpine, debian etc.) We will keep you posted.

@avarabei
Copy link

Not sure, but may be this can help with libc: https://github.com/docker/compose/blob/master/Dockerfile.run

@csandanov
Copy link

Can it work with http://www.unixodbc.org/? Alpine already has in repositories

@csandanov
Copy link

Any progress on that?

@ruudboon
Copy link

Any updates?

@David-Engel
Copy link
Contributor

@ruudboon No updates. Alpine still is not a supported Linux distribution for the ODBC Driver. We will keep Alpine in mind as we evaluate supporting additional distributions.

Regards,
David

@benyanke
Copy link

benyanke commented Apr 9, 2018

This is becoming a dealbreaker for me, especially as I attempt to put more of my apps into docker, using alpine, which is more-or-less best practice for most situations.

Is there any way, even with some hacks, to get this working in alpine?

@rommkaa
Copy link

rommkaa commented Jul 19, 2018

perhaps this image is suitable for installing msphpsql https://github.com/frol/docker-alpine-glibc

@thsmrtone1
Copy link

It would be awesome to see support for Alpine

@alsilva86
Copy link

Dear Microsoft, please note that everybody is creating containers on Alpine distro's, could you please help my DevOps life?

Br

@romeugodoi
Copy link

It would be awesome to see support for Alpine Linux 👍

@ikwijaya
Copy link

update..?

@yitam
Copy link
Contributor

yitam commented Sep 26, 2018

It's in our backlog, but as @David-Engel said above:

No updates. Alpine still is not a supported Linux distribution for the ODBC Driver. We will keep Alpine in mind as we evaluate supporting additional distributions.

@herojhc
Copy link

herojhc commented Nov 8, 2018

Is there any progress?

@alsilva86
Copy link

alsilva86 commented Nov 8, 2018 via email

@SanderSander
Copy link

Thats why the open source community struggles so much against Java and other technologies

Isn't it the other way around? The open source community doesn't struggle.
Microsoft struggles to support new technology like docker / alpine.

@benyanke
Copy link

We simply gave up using Alpine and moved on.

That's easy for you to say, but alpine provides a benefit to many users, and many containers and environments are build on it. It's far from "academic." It's "I have hundreds of alpine containers, and if this driver doesn't work on alpine, I can't use it."

By not supporting alpine, they're not supporting a place where their users want to run their software.

@David-Engel
Copy link
Contributor

Microsoft struggles to support new technology like docker / alpine.

Microsoft fully supports Docker containers and is very much on board with that model. Alpine is just one Linux distribution that happens to be optimized for the container model.

Supporting another platform is not just adding some code and some tests to your existing code base and CI. It also means ensuring all your dependencies are on the new platform, creating new packaging and new test (and probably build) infrastructure that has to be maintained going forward. That all costs money and money is not infinite so people have to prioritize. Alpine has a lot going for it and it is getting a lot of traction in the container world. That has not gone unnoticed.

@mchenx
Copy link

mchenx commented Apr 18, 2019

looking for msodbcsql17 for alpine too
maybe it's time to move to centos ......

@ghost
Copy link

ghost commented May 14, 2019

One more 👍 thumbsup vote for Microsoft ODBC support for alpine

Currently test script doesn't work.

php -i | grep sqlsrv
/etc/php7/conf.d/30-sqlsrv.ini,
/etc/php7/conf.d/35-pdo_sqlsrv.ini,
Registered PHP Streams => compress.zlib, https, ftps, php, file, glob, data, http, ftp, zip, phar, sqlsrv
PDO drivers => dblib, sqlsrv
pdo_sqlsrv
pdo_sqlsrv support => enabled
pdo_sqlsrv.client_buffer_max_kb_size => 10240 => 10240
pdo_sqlsrv.log_severity => 0 => 0
sqlsrv
sqlsrv support => enabled
<?php

$conn_array = array (
    "UID" => "sa",
    "PWD" => "secretpassword",
    "Database" => "testdatabase",
);
$conn = sqlsrv_connect("192.168.1.3, 5555", $conn_array);
if ($conn){
    echo "connected";
    if(($result = sqlsrv_query($conn,"SELECT * FROM dbo.table")) !== false){
        while( $obj = sqlsrv_fetch_object( $result )) {
              echo $obj->colName.'<br />';
        }
    }
}else{
    die(print_r(sqlsrv_errors(), true));
}
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
        )
)

Tried to make frankenstein with FROM frolvlad/alpine-glibc alpine with glibc hackish way

bash-4.4# apk add nano
(1/2) Installing libmagic (5.36-r0)
(2/2) Installing nano (3.2-r0)
Executing busybox-1.29.3-r10.trigger
Executing glibc-bin-2.29-r0.trigger
/usr/glibc-compat/sbin/ldconfig: /usr/lib/libsodium.so.23 is not a symbolic link

OK: 78 MiB in 92 packages
bash-4.4# ldd /usr/lib/libsodium.so.23
	ldd (0x7f60dfa83000)
	libc.musl-x86_64.so.1 => ldd (0x7f60dfa83000)

alpine glibc version doesn't have docker-php-ext-install

+ docker-php-ext-install pdo_dblib
/bin/sh: docker-php-ext-install: not found

So fallbacked to pecl install with apk add g++ make

@ZaxLofful
Copy link

I would also like for this to happen, does anyone know the team internally at Microsoft? I would like to try and work with them.

Please, DM me if you have any contacts at Microsoft that can help with this situation or if you know the team working on it.

@David-Engel
Copy link
Contributor

@ZaxLofful Most of the top contributors here are working for Microsoft. I'm the PM for drivers for SQL Server. Alpine support is on the roadmap for the ODBC and PHP drivers. It's just a matter of getting it prioritized and funded. See my previous comment for details. Upvoting this issue provides the best user feedback to the right people for getting Alpine support prioritized.

@SanderSander
Copy link

SanderSander commented Jul 17, 2019

@David-Engel

It's just a matter of getting it prioritized and funded.

It would be so nice to use alpine based containers connecting to mssql containers, and mssql is a good product right? The funds shouldn't be a problem (my opinion) cause the entry level for using mssql would be lower when the drivers are easily integrated. I mean there are so much use-cases to prefer mssql above other sql solutions.

@alsilva86
Copy link

alsilva86 commented Jul 17, 2019 via email

@devrsw
Copy link

devrsw commented Nov 19, 2019

We've been using Pymssql, but are now being forced to switch to pyodbc due to the issue above. We're running Alpine on our containers, so we're hopeful that an Alpine-compatible driver can be released soon.

@nkierdem
Copy link

nkierdem commented Feb 3, 2020

its there guys :)

https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15#alpine-linux

@bkraul
Copy link

bkraul commented Feb 3, 2020

Far from being ready. The pecl compilation for the php extensions fails with:

/tmp/pear/temp/sqlsrv/shared/xplat.h:30:10: fatal error: sql.h: No such file or directory

Plus, there are errors on the MS instructions page. curls missing the -O option, and also the file names for verification being wrong (not matched what was downloaded).

@yitam
Copy link
Contributor

yitam commented Feb 3, 2020

Thanks for the update. We will double check the documentation.
For pecl compilation to work, please install unixodbc-dev first.

@acelaya
Copy link

acelaya commented Feb 3, 2020

This is what I did on an alpine-based Dockerfile to install it:

RUN wget https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.5.1.1-1_amd64.apk && \
    wget https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_17.5.1.1-1_amd64.apk && \
    apk add --allow-untrusted msodbcsql17_17.5.1.1-1_amd64.apk && \
    apk add --allow-untrusted mssql-tools_17.5.1.1-1_amd64.apk && \
    apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS unixodbc-dev && \
    pecl install pdo_sqlsrv && \
    docker-php-ext-enable pdo_sqlsrv && \
    apk del .phpize-deps && \
    rm msodbcsql17_17.5.1.1-1_amd64.apk && \
    rm mssql-tools_17.5.1.1-1_amd64.apk

I'm about to test if it works, but it compiled with no errors.

@yitam
Copy link
Contributor

yitam commented Feb 3, 2020

Thanks for the update @acelaya

Just so you know, for 5.8.0 the support for Alpine is experimental. In particular, we do not currently recommend enabling both drivers because there are some known issues. If you do encounter new issues when using either sqlsrv or pdo_sqlsrv, please create a new issue for us to keep track.

@acelaya
Copy link

acelaya commented Feb 3, 2020

Thanks for the tip @yitam. I have just left pdo_sqlsrv and removed the other one.

Then I have done some tests and it seems to partially work, but I also get this error: locale::facet::_S_create_c_locale name not valid.

By searching a bit you can find that's because of missing locale configuration. However, while it is easy to solve on other distros, it's not as easy to workaround on alpine.

I will continue investigating.

@yitam
Copy link
Contributor

yitam commented Feb 3, 2020

Thanks @acelaya
We also encountered that in our testing, and for now, it seems export LC_ALL=C is a workaround. We are investigating on our side as well.

@acelaya
Copy link

acelaya commented Feb 3, 2020

Yeah!! That did the trick 😃

Everything is working on my set-up now.

@David-Engel
Copy link
Contributor

Just so you know, for 5.8.0 the support for Alpine is experimental. In particular, we do not currently recommend enabling both drivers because there are some known issues. If you do encounter new issues when using either sqlsrv or pdo_sqlsrv, please create a new issue for us to keep track.

I just want to reiterate @yitam's comment. Alpine has some peculiar differences compared to other distributions. Given our testing and the issues we noted in the release notes, we were not confident calling this PHP release production-ready for Alpine. Our thought is to let it get run through some paces by others and identify any issues, so please file them in this repo if you encounter them. If we need to, we can release an update to address any critical issues.

@bkraul
Copy link

bkraul commented Feb 4, 2020

So for me using @acelaya 's instructions (modified) I was able to install everything, including both pecl extensions. However, upon testing, I am getting:

Fatal error: sqlsrv_connect: Unknown exception caught. in /app/core.php on line 12 (place where I am calling the connection)

With this happening at the $conn = sqlsrv_connect( $host, $connectionOptions); point. So I am not really able to get much info out of this.

@david-puglielli
Copy link
Contributor

@bkraul This is a known issue. If possible, you can work around it by setting CharacterSet to UTF-8 in the connection options.

@bkraul
Copy link

bkraul commented Feb 4, 2020

@david-puglielli Thanks. That did work. I am assuming at some point specifying this will not be needed? And are there any known complications with the use of UTF-8 for connections where it hasn't been used before?

@yitam
Copy link
Contributor

yitam commented Feb 4, 2020

@bkraul , as I mentioned to @acelaya export LC_ALL=C is another workaround for the time being.

@bkraul
Copy link

bkraul commented Feb 4, 2020

@yitam I'm trying to figure out where I am supposed to place the export LC_ALL=C. I am putting it in the RUN section of my Dockerfile, but it does not seem to affect anything. The script still errors unless I include the CharacterSet option. This is what I have:

RUN set -x \
    # install the build pre-requisites.
    && apk add --no-cache --virtual .build-deps autoconf file g++ make pkgconf re2c php7-dev unixodbc-dev libmcrypt-dev \
    # install mssql drivers
    && curl https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.5.1.1-1_amd64.apk -O \
    && curl https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_17.5.1.1-1_amd64.apk -O \
    && apk add --allow-untrusted msodbcsql17_17.5.1.1-1_amd64.apk \
    && apk add --allow-untrusted mssql-tools_17.5.1.1-1_amd64.apk \
    # at the mssql-tools binary to the path.
    && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile \
    && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc \
    && /bin/bash -c "source ~/.bashrc" \
    # install the pecl extensions.
    && pecl install mcrypt-1.0.2 \
    && pecl install pdo_sqlsrv \
    && pecl install sqlsrv \
    && pecl install igbinary \
    && pecl install msgpack \
    # enable the extensions.
    && echo extension=mcrypt.so > /etc/php7/conf.d/20-mcrypt.ini \
    && echo extension=pdo_sqlsrv.so > /etc/php7/conf.d/30-pdo_sqlsrv.ini \
    && echo extension=sqlsrv.so > /etc/php7/conf.d/20-sqlsrv.ini \
    && echo extension=igbinary.so > /etc/php7/conf.d/20-igbinary.ini \
    && echo extension=msgpack.so > /etc/php7/conf.d/20-msgpack.ini \
    # locale workaround.
    && export LC_ALL=C \
    # perform image cleanup.
    && apk del .build-deps \
    && rm msodbcsql17_17.5.1.1-1_amd64.apk \
    && rm mssql-tools_17.5.1.1-1_amd64.apk \
    && docker-run-bootstrap \
    && docker-image-cleanup

@yitam
Copy link
Contributor

yitam commented Feb 4, 2020

@bkraul when we were testing adding ENV LC_ALL=C to the Dockerfile seemed to work. Can you try that?

@bkraul
Copy link

bkraul commented Feb 4, 2020

@yitam That seems to do the trick. Thank you for your quick replies. Very excited at the prospect of this going on prod soon. It slashes my image size by 2/3!!

@marceloavan
Copy link

marceloavan commented Feb 6, 2020

its there guys :)

https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15#alpine-linux

Just a little detail: the pt-br version of documentation does not contain the Alpine Linux section. It would be good add there also.

@David-Engel
Copy link
Contributor

Just a little detail: the pt-br version of documentation does not contain the Alpine Linux section. It would be good add there also.

Translation of the online docs is automated and out of our control. It's probably just taking a while or something is stuck in whatever translation pipeline the doc team uses. I assume it will get there eventually.

@yitam
Copy link
Contributor

yitam commented Apr 20, 2020

Hi all, please note that 5.8.1 hotfix is released! The workarounds mentioned above are no longer required. Please try it out and let us know if you run into any issues.

@croblesm
Copy link

In case you guys are still looking for a minimal "mssql-tools" with Alpine. I was able to create one, you can find the Dockerfile here.

Let me know if you have any questions or comments.

Cheers,

@neclimdul
Copy link

It was a bit tricky getting the combination of pecl commands and tracking down the odbc drivers(which aren't mentioned in the documentation) but once I did it was seamless. Nice to walk away from a new segfault in FreeTDS instead of tracing it out and just being able to use this. Thank you! Keep up the great work!

@yitam
Copy link
Contributor

yitam commented Jun 18, 2020

Thanks @neclimdul and glad that it works for you!

In case anyone else is looking for the documentation for installing sqlsrv drivers in Alpine Linux, this is the section for Alpine 3.11, which references the ODBC Driver 17

@neclimdul
Copy link

@yitam sorry. yeah that was perfect but I found that documentation here. I meant its not documented in the php extension install instructions here: https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15

@neclimdul
Copy link

oh no it is i just hadn't found it... ignore all the noise. Sorry everyone :(

@StefanSchoof
Copy link

Is there any work done to get the sql driver direct into official alpine packages, so that

RUN docker-php-ext-install pdo_sqlsrv

is enough?

@yitam
Copy link
Contributor

yitam commented Aug 12, 2020

No, @StefanSchoof , but please check this out:
https://github.com/mlocati/docker-php-extension-installer

I wrote a simple shell script install_drivers.sh based on the latest ODBC instructions

curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.6.1.1-1_amd64.apk
curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_17.6.1.1-1_amd64.apk
printf '\n' | apk add --allow-untrusted msodbcsql17_17.6.1.1-1_amd64.apk
printf '\n' | apk add --allow-untrusted mssql-tools_17.6.1.1-1_amd64.apk
ln -sfnv /opt/mssql-tools/bin/* /usr/bin

Write a simple php script for checking client info:

<?php
$server = <host>;
$uid = <user>;
$pwd = <password>;
$conn = new PDO("sqlsrv:server=$server", $uid, $pwd);

$attr = $conn->getAttribute(constant('PDO::ATTR_CLIENT_VERSION'));
$version = substr($attr['DriverVer'], 0, 2);
print_r($conn->getAttribute(PDO::ATTR_CLIENT_VERSION));
unset($conn);
?>

This is the Dockerfile I've tested:

FROM php:7.4.9-fpm-alpine3.12
ADD install_drivers.sh /tmp
ADD pdo_client_info.php /tmp
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
RUN chmod +x /tmp/install_drivers.sh && \
    /tmp/install_drivers.sh && \
    install-php-extensions sqlsrv pdo_sqlsrv 

This is the output when running it interactively:
image

@aniruddha-dnb
Copy link

This is what I did on an alpine-based Dockerfile to install it:

RUN wget https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.5.1.1-1_amd64.apk && \
    wget https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_17.5.1.1-1_amd64.apk && \
    apk add --allow-untrusted msodbcsql17_17.5.1.1-1_amd64.apk && \
    apk add --allow-untrusted mssql-tools_17.5.1.1-1_amd64.apk && \
    apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS unixodbc-dev && \
    pecl install pdo_sqlsrv && \
    docker-php-ext-enable pdo_sqlsrv && \
    apk del .phpize-deps && \
    rm msodbcsql17_17.5.1.1-1_amd64.apk && \
    rm mssql-tools_17.5.1.1-1_amd64.apk

I'm about to test if it works, but it compiled with no errors.

Its works for me as well , but I'm getting this error. Any Idea ?
SQLSTATE[HYT00]: [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired
File: /var/www/vendor/faapz/pdo/src/Database.php

@inri13666
Copy link

@aniruddha-dnb please provide MsSQL version and keep in mind that latest versions require latest version of libraries

more info here https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver16&tabs=alpine18-install%2Calpine17-install%2Cdebian8-install%2Credhat7-13-install%2Crhel7-offline#17

As well as I see no info about your connection, seems you have incorrect config and try to connect to host IP

Please provide the ping or telnet output from docker image to the host what you are trying to connect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests