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

No talk, all code.

# Microsoft SQL Server Prerequisites
RUN apt-get update \
    && apt-get install -y --no-install-recommends gnupg \
    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update \
    && apt-get install -y --no-install-recommends locales apt-transport-https \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
    && locale-gen \
    && echo msodbcsql17 msodbcsql/ACCEPT_EULA boolean true |  debconf-set-selections \
    && apt-get -y --no-install-recommends --allow-unauthenticated install unixodbc-dev \
    && apt-get -y --no-install-recommends --allow-unauthenticated install msodbcsql17 \
    && apt-get -y --no-install-recommends --allow-unauthenticated install mssql-tools \
    && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install  pdo pdo_mysql
RUN curl http://pecl.php.net/get/sqlsrv -o /tmp/sqlsrv.tgz \
    && pear install /tmp/sqlsrv.tgz \
    && curl http://pecl.php.net/get/pdo_sqlsrv -o /tmp/pdo_sqlsrv.tgz  \
    && pear install /tmp/pdo_sqlsrv.tgz \
    && 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.