sburnwal
sburnwal

Reputation: 165

Locale.Error with building python based docker

I am new to docker and would appreciate if someone can help me get rid of this error while building the docker image. It is giving some kind of locale error. How can I get rid of this error ?

Collecting pip
Downloading pip-8.1.1-py2.py3-none-any.whl (1.2MB)
Collecting setuptools
Downloading setuptools-20.3.1-py2.py3-none-any.whl (508kB)
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-8.1.1 setuptools-20.3.1 wheel-0.29.0
+ pip install --no-cache-dir --upgrade pip==8.0.2
Traceback (most recent call last):
File "/usr/bin/pip", line 11, in 
sys.exit(main())
File "/usr/lib/python2.7/site-packages/pip/__init__.py", line 215, in main
locale.setlocale(locale.LC_ALL, '')
File "/usr/lib64/python2.7/locale.py", line 547, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
The command '/bin/sh -c set -ex && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" && curl -fSL 'https://bootstrap.pypa.io/get-pip.py' | python2 && pip install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION' returned a non-zero code: 1

This is my Dockerfile:

FROM mybase:1.0.7

RUN set -x \
&& yum install -y python-devel libffi-devel python-cffi \
&& yum clean all

ENV LANG C.UTF-8

ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF

ENV PYTHON_VERSION 2.7.11

ENV PYTHON_PIP_VERSION 8.0.2

RUN set -ex \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
&& curl -fSL 'https://bootstrap.pypa.io/get-pip.py' | python2 \
&& pip install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION

RUN pip install --no-cache-dir virtualenv

CMD ["python2"]

Upvotes: 0

Views: 1344

Answers (1)

RedBaron
RedBaron

Reputation: 4745

The locale.setlocale docs say the locale should be valid. If an empty string is passed, the LANG variable is used to set the locale. This error is probably caused because your LANG is not a supported locale

In your docker script, you set LANG to C.UTF-8. It looks like C.UTF-8 is not a supported locale in glibc and I am guessing hence in Python (See this and this).

You can set your LANG to a supported type like en_US.UTF-8 (The default on my computer).

On Python-2.6, I get the following results

Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
'en_US.utf8'
>>> locale.setlocale(locale.LC_ALL, "C.UTF-8")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.6/locale.py", line 513, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
>>> locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
'en_US.UTF-8'
>>> locale.setlocale(locale.LC_ALL, "de_DE.UTF-8")
'de_DE.UTF-8'

You can view the locales available on your computer by running

$ locale -a

Upvotes: 1

Related Questions