Mssql-docker: sqlcmd ungraceful termination without en_US.UTF-8 UTF-8 locale

Created on 28 Sep 2017  路  7Comments  路  Source: microsoft/mssql-docker

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 https://github.com/Microsoft/mssql-docker/issues/8#issuecomment-271357288 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.

mssql-server-linux

Most helpful comment

You need to have "en_US.UTF-8" along with your other locale:

Only "nb_NO.UTF-8" fails:

root@011bfaee687f:/test/sensiotools/sensiotools# /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

^C^Z
[1]+  Venter                  /opt/mssql-tools/bin/sqlcmd
root@011bfaee687f:/test/sensiotools/sensiotools# locale
LANG=nb_NO.UTF-8
LANGUAGE=
LC_CTYPE="nb_NO.UTF-8"
LC_NUMERIC="nb_NO.UTF-8"
LC_TIME="nb_NO.UTF-8"
LC_COLLATE="nb_NO.UTF-8"
LC_MONETARY="nb_NO.UTF-8"
LC_MESSAGES="nb_NO.UTF-8"
LC_PAPER="nb_NO.UTF-8"
LC_NAME="nb_NO.UTF-8"
LC_ADDRESS="nb_NO.UTF-8"
LC_TELEPHONE="nb_NO.UTF-8"
LC_MEASUREMENT="nb_NO.UTF-8"
LC_IDENTIFICATION="nb_NO.UTF-8"
LC_ALL=
root@011bfaee687f:/test/sensiotools/sensiotools# dpkg-query -l mssql-tools
脴nsket=Ukjent/Installer/Fjern/Rens ut/Hold tilbake
| Status=Ikke/Inst/Oppsettsfiler/Ikke pakket ut/HalvT-satt-opp/Halvt-inst/Ut-ventende
|/ Feil?=(ingen)/M氓 inst. p氓 nytt (Status,Feil: versalar=dumt)
||/ Navn                                          Versjon                     Architecture                Beskrivelse
+++-=============================================-===========================-===========================-===============================================================================================
ii  mssql-tools                                   14.0.6.0-1                  amd64                       Tools for Microsoft(R) SQL Server(R)

I add "en_US.UTF-8" along with my previous one it works:

root@011bfaee687f:/test/sensiotools/sensiotools# echo "nb_NO.UTF-8 UTF-8" > /etc/locale.gen
root@011bfaee687f:/test/sensiotools/sensiotools# echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
root@011bfaee687f:/test/sensiotools/sensiotools# locale-gen
Generating locales (this might take a while)...
  en_US.UTF-8... done
  nb_NO.UTF-8... done
Generation complete.
root@011bfaee687f:/test/sensiotools/sensiotools# /opt/mssql-tools/bin/sqlcmd
Microsoft (R) SQL Server Command Line Tool
Version 13.1.0007.0 Linux
Copyright (c) 2012 Microsoft. All rights reserved.
:

All 7 comments

You need to have "en_US.UTF-8" along with your other locale:

Only "nb_NO.UTF-8" fails:

root@011bfaee687f:/test/sensiotools/sensiotools# /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

^C^Z
[1]+  Venter                  /opt/mssql-tools/bin/sqlcmd
root@011bfaee687f:/test/sensiotools/sensiotools# locale
LANG=nb_NO.UTF-8
LANGUAGE=
LC_CTYPE="nb_NO.UTF-8"
LC_NUMERIC="nb_NO.UTF-8"
LC_TIME="nb_NO.UTF-8"
LC_COLLATE="nb_NO.UTF-8"
LC_MONETARY="nb_NO.UTF-8"
LC_MESSAGES="nb_NO.UTF-8"
LC_PAPER="nb_NO.UTF-8"
LC_NAME="nb_NO.UTF-8"
LC_ADDRESS="nb_NO.UTF-8"
LC_TELEPHONE="nb_NO.UTF-8"
LC_MEASUREMENT="nb_NO.UTF-8"
LC_IDENTIFICATION="nb_NO.UTF-8"
LC_ALL=
root@011bfaee687f:/test/sensiotools/sensiotools# dpkg-query -l mssql-tools
脴nsket=Ukjent/Installer/Fjern/Rens ut/Hold tilbake
| Status=Ikke/Inst/Oppsettsfiler/Ikke pakket ut/HalvT-satt-opp/Halvt-inst/Ut-ventende
|/ Feil?=(ingen)/M氓 inst. p氓 nytt (Status,Feil: versalar=dumt)
||/ Navn                                          Versjon                     Architecture                Beskrivelse
+++-=============================================-===========================-===========================-===============================================================================================
ii  mssql-tools                                   14.0.6.0-1                  amd64                       Tools for Microsoft(R) SQL Server(R)

I add "en_US.UTF-8" along with my previous one it works:

root@011bfaee687f:/test/sensiotools/sensiotools# echo "nb_NO.UTF-8 UTF-8" > /etc/locale.gen
root@011bfaee687f:/test/sensiotools/sensiotools# echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
root@011bfaee687f:/test/sensiotools/sensiotools# locale-gen
Generating locales (this might take a while)...
  en_US.UTF-8... done
  nb_NO.UTF-8... done
Generation complete.
root@011bfaee687f:/test/sensiotools/sensiotools# /opt/mssql-tools/bin/sqlcmd
Microsoft (R) SQL Server Command Line Tool
Version 13.1.0007.0 Linux
Copyright (c) 2012 Microsoft. All rights reserved.
:

Thanks, I had mine unset on a vps for ages and never thought it an issue. To be honest it _should_ cope without. Most linux things are able to assume a default or cope without entirely. Warnings aplenty mind you as I've seen many times in the past with other linux build processes etc.

fenchu's answer solved the issue for me.

My locale is set but the problem is still present

@bizmate did you add:

echo "nb_NO.UTF-8 UTF-8" > /etc/locale.gen
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen

then run locale-gen and the issue is still there?

@ccalderon911217 i just realised this is for docker, so this must be for a specific version of linux. I am seeing the problem on a centos7 VM (not on FROM ubuntu:16.04) where

[vagrant@localhost ~]$ localectl status
   System Locale: LANG=en_GB.utf8
       VC Keymap: uk
      X11 Layout: gb

/etc/locale.gen does not exist and have only one locale

[vagrant@localhost ~]$ localectl list-locales
en_GB.utf8

@bizmate yeah this is for ubuntu:latest I believe so I would be different for a centOS.

Was this page helpful?
0 / 5 - 0 ratings