MSQL on linux : Fix locale::facet::_S_create_c_locale name not valid

https://github.com/Microsoft/mssql-docker/issues/163

https://github.com/Creepsky/creepMiner/issues/122

First, this report is not just about issue with mssql-docker but I suspect it is related to about mssql-tools for Linux in general, more specifically the sqlcmd. (Not sure where would be better and more accessible by others place to report it.)

I run docker container based on ubuntu:latest image and I install the mssql-tools in order to be able to run sqlcmd (I’m connecting to SQL Server in separate container).

Here is my Dockerfile

RUN apt-get -qy update && apt-get -qy install --no-upgrade --no-install-recommends \
        apt-transport-https \
        apt-utils \
        curl \
        software-properties-common

RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN add-apt-repository "$(curl -s https://packages.microsoft.com/config/ubuntu/16.04/prod.list)"

RUN ACCEPT_EULA=Y apt-get -qy install --no-upgrade --no-install-recommends \
        msodbcsql \
        mssql-tools \
        unixodbc-dev

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

Then I do docker exec -it bash and BANG!

root@2531848bc8e4:/# /opt/mssql-tools/bin/sqlcmd
terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid

The SQL Server installation docs do not mention anything about specific locale required.

The only source of any hints is the Dockerfile-s like https://github.com/Microsoft/mssql-docker/blob/master/oss-drivers/msphpsql/Dockerfile, which contain:

# install necessary locales
RUN apt-get install -y locales \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
    && locale-gen

If digs deeper, one can find this comment #8 (comment) for the seemingly unrelated issue #8

Clearly, this is a bug in the implementation of the mssql-tools, specifically the sqlcmd which should detect it runs in environment with incompatible locale and, obviously, print an informative message, not just terminate.