WILT: MS SQL Server on Docker (Linux) for PHP

No talk, all code.

 1# Microsoft SQL Server Prerequisites
 2RUN apt-get update \
 3    && apt-get install -y --no-install-recommends gnupg \
 4    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
 5    && curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list \
 6    && apt-get update \
 7    && apt-get install -y --no-install-recommends locales apt-transport-https \
 8    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
 9    && locale-gen \
10    && echo msodbcsql17 msodbcsql/ACCEPT_EULA boolean true |  debconf-set-selections \
11    && apt-get -y --no-install-recommends --allow-unauthenticated install unixodbc-dev \
12    && apt-get -y --no-install-recommends --allow-unauthenticated install msodbcsql17 \
13    && apt-get -y --no-install-recommends --allow-unauthenticated install mssql-tools \
14    && rm -rf /var/lib/apt/lists/*
15RUN docker-php-ext-install  pdo pdo_mysql
16RUN curl http://pecl.php.net/get/sqlsrv -o /tmp/sqlsrv.tgz \
17    && pear install /tmp/sqlsrv.tgz \
18    && curl http://pecl.php.net/get/pdo_sqlsrv -o /tmp/pdo_sqlsrv.tgz  \
19    && pear install /tmp/pdo_sqlsrv.tgz \
20    && docker-php-ext-enable sqlsrv pdo_sqlsrv 

OK, some talk.

https://laravel-news.com/install-microsoft-sql-drivers-php-7-docker got me close. The pecl install sqlsrv pdo_sqlsrv command was not working, as Pecl was claiming the modules did not exist. https://stackoverflow.com/questions/45220954/pecl-install-sqlsrv-returns-no-releases-available-for-package got me closer being able to target a specific version, but going to the pecl page showed a way to get the latest stable release so I used that instead. I had to remember to run Update after adding those packages - I couldn't put them in earlier because the gnupg was required to get them in the first place.

I had to install unixopdbc-dev as otherwise I couldn't compile the tgz extensions.

Also advice from a local Docker expert reminded me to add the rm -rf /var/lib/apt/lists/* command after any RUN that uses apt-get, in order to remove artifacts that could bloat the image.