도커, 알파인 및 matplotlib


11

현재 알파인을 사용하여 도커 이미지 중 하나를 축소하려고합니다.

FROM python:2.7-alpine

그러나 matplotlib.h를 설치하는 데 문제가 있습니다.

EOF
warning: no previously-included files matching '*.pyo' found anywhere in distribution
warning: no previously-included files matching '*.pyd' found anywhere in distribution
numpy/core/src/multiarray/numpyos.c:18:21: fatal error: xlocale.h: No such file or directory
compilation terminated.
numpy/core/src/multiarray/numpyos.c:18:21: fatal error: xlocale.h: No such file or directory
compilation terminated.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-kCID_8/matplotlib/setup.py", line 383, in <module>
    **extra_args
  File "/usr/local/lib/python2.7/distutils/core.py", line 111, in setup
    _setup_distribution = dist = klass(attrs)
  File "/usr/local/lib/python2.7/site-packages/setuptools/dist.py", line 269, in __init__
    self.fetch_build_eggs(attrs['setup_requires'])
  File "/usr/local/lib/python2.7/site-packages/setuptools/dist.py", line 313, in fetch_build_eggs
    replace_conflicting=True,
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 826, in resolve
    dist = best[req.key] = env.best_match(req, ws, installer)
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1071, in best_match
    return self.obtain(req, installer)
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1083, in obtain
    return installer(requirement)
  File "/usr/local/lib/python2.7/site-packages/setuptools/dist.py", line 380, in fetch_build_egg
    return cmd.easy_install(req)
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 640, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 670, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 850, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1078, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1066, in run_setup
    raise DistutilsError("Setup script exited with %s" % (v.args[0],))
distutils.errors.DistutilsError: Setup script exited with error: Command "gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DHAVE_CBLAS -Ibuild/src.linux-x86_64-2.7/numpy/core/src/private -Inumpy/core/include -Ibuild/src.linux-x86_64-2.7/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/usr/local/include/python2.7 -Ibuild/src.linux-x86_64-2.7/numpy/core/src/private -Ibuild/src.linux-x86_64-2.7/numpy/core/src/private -Ibuild/src.linux-x86_64-2.7/numpy/core/src/private -c numpy/core/src/multiarray/numpyos.c -o build/temp.linux-x86_64-2.7/numpy/core/src/multiarray/numpyos.o" failed with exit status 1

아마이 때문일 것입니다 musl.

내 관련 비트는 다음과 같습니다 Dockerfile.

# xmlsec is only available in the testing repo
RUN apk add --no-cache --virtual .build-deps \
  xmlsec \
  xmlsec-dev \
  py-numpy \
  py-numpy-dev \
  --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ \
  --allow-untrusted

RUN apk add --no-cache --virtual .build-deps \
  build-base \
  postgresql-dev \
  libffi-dev \
  nodejs \
  swig \
  git \
  libpng-dev \
  freetype-dev \
  libxml2-dev \
  libxslt-dev \
  python-dev \
  musl-dev \
  tk-dev \
  gfortran \
  py-setuptools \
  netcat-openbsd

RUN pip install -r requirements.txt

이것은 내 requirements.txt입니다.

setuptools==19.7
alabaster==0.7.4
amqp==1.4.6
anyjson==0.3.3
authy==2.1.2
awscli==1.9.12
Babel==1.3
backports.ssl-match-hostname==3.4.0.2
blessings==1.6
boto==2.9.9
certifi==2015.4.28
click==4.0
cryptography==1.0.1
Django==1.8.2
django-oauth-toolkit==0.8.1
django-appconf==1.0.1
django-compressor==1.5
django-cors-headers==1.1.0
django-coverage==1.2.4
django-crispy-forms==1.5.2
django-crontab==0.6.0
django-debug-panel==0.8.1
django-debug-toolbar==1.3.0
django-easy-pdf==0.1.0
django-email-extras==0.3.1
django-filter==0.10.0
django-forms-builder==0.11.1
django-libsass==0.3
django-markdown-deux==1.0.5
django-model-utils==2.2
django-nose==1.4
django-pgjson==0.3.1
django-phonenumber-field==0.7.2
django-pickling==0.1
django-ratelimit==0.6.0
django-redis==4.0.0
djangorestframework==3.3.1
djangorestframework-csv==1.3.4
django-rq==0.7.0
django-s3-cache==1.4.2
django-sphinx==2.2.4
django-storages==1.1.8
django-templatetag-handlebars==1.3.0
django-timedeltafield==0.7.10
django-twilio==0.8.0
docutils==0.12
ecdsa==0.11
extras==0.0.3
factory-boy==2.5.2
fake-factory==0.5.1
flex==4.3.0
functools32==3.2.3-1
gdata==2.0.18
gnureadline==6.3.3
greenlet==0.4.7
gunicorn==19.3.0
html5lib==0.999
httplib2==0.9.1
httpretty==0.8.10
inflection==0.3.1
ipdb==0.8
ipython==3.1.0
Jinja2==2.7.3
jsonschema==2.5.1
libsass==0.8.2
linecache2==1.0.0
lockfile==0.9.1
lxml==3.4.4
matplotlib==1.5.0
mimeparse==0.1.3
mistune==0.6
mock==1.3.0
newrelic==2.50.0.39
nose==1.3.6
nose-progressive==1.5.1
numpy==1.9.2
oauth2client==1.4.11
oauthlib==0.7.2
pandas==0.16.1
paramiko==1.15.2
pbr==1.0.1
pep8==1.6.2
phonenumbers==7.0.9
Pillow==2.8.1
pipdeptree==0.4.2
progressbar33==2.4
psycopg2==2.5.5
ptyprocess==0.5
pyasn1==0.1.7
pyasn1-modules==0.0.5
pycrypto==2.6.1
Pygments==2.0.2
PyJWT==1.3.0
pyOpenSSL==0.13
PyPDF2==1.24
python-daemon==1.6
python-dateutil==2.4.2
python-gnupg==0.3.7
python-logstash==0.4.6
python-memcached==1.54
python-mimeparse==0.1.4
python-openid==2.2.5
python-saml==2.1.3
python-social-auth==0.2.12
pytz==2015.4
PyYAML==3.11
pyzmq==14.6.0
raven==5.5.0
redis==2.10.3
reportlab==3.1.44
requests==2.7.0
requests-oauthlib==0.5.0
rq==0.5.2
rq-scheduler==0.5.1
rsa==3.1.4
simplejson==3.7.2
six==1.10.0
soaplib==2.0.0-beta2
sorl-thumbnail==12.2
Sphinx==1.3.1
sphinx-me==0.3
sqlparse==0.1.15
ssh==1.8.0
stripe==1.27.1
suds==0.4
terminado==0.5
testtools==1.8.0
traceback2==1.4.0
Unidecode==0.4.17
unittest2==1.0.1
uritemplate==0.6
vobject==0.6.6
Werkzeug==0.9.6
whitenoise==1.0.6
xhtml2pdf==0.0.6
django-absoluteuri==1.1.0

설치하려면 어떻게해야합니까?

답변:


13

다음을 추가 하여이 문제를 해결했습니다.

RUN ln -s /usr/include/locale.h /usr/include/xlocale.h

모든 것이 제대로 설치 될 수 있습니다. 그러나 그것이 좋은 습관인지 확실하지 않습니다.


나는 당신이 어디에서 왔는지 이해합니다. 그러나 Dockerfile에서 이것을 더 잘 정리 할 수 ​​있다고 생각합니다 (주석 의이 정확한 게시물에 대한 적절한 링크로). Docker는 비평가에도 불구하고 이와 같은 것들 때문에 부분적으로 인상적입니다.
— lol

이것은 Cygwin에서도 작동합니다. Numpy는 사용 가능한 경우 xlocale.h를로드하려고 시도하며 어떤 이유로 Cygwin에서 모든 위치에서 사용할 수 있다고 생각하지만 xlocale.h의 특수 기능에 의존하지 않습니다.
— CMCDragonkai

무엇을 제공 /usr/include/locale.h합니까? 알파인 이미지를 사용하고 있으며 이미 설치되어 make python gcc libffi-dev linux-headers libgcc libstdc++있지만 필요한 파일이 링크되어 있지 않습니다.
— MikeM

@ MichaelMügge 이것이 musl-dev패키지입니다
— Céline Aussourd

2

당신은 아마 사용하는 고산 리눅스 고정 표시기 이미지를 사용할 필요가 glibc및 교체 musl-dev에 glibc-headers누락 된 헤더 파일에 번들로 제공되기 때문에를 glibc-headers.

glibc활성화 된 고산 리눅스 도커 이미지 를 찾을 때 Docker Hub의 모든 최상위 결과는 APK 패키지에 대해 동일한 소스 를 사용 glibc합니다.

이 빌드에는 헤더가 포함되어 있지 않지만 누락 된 파일이있는 다른 하위 패키지를 포함하여 조정하지 않을 수 있습니다.

headers() {
  mkdir -p "$subpkgdir"/usr/glibc-compat
  cp -a "$srcdir"/usr/glibc-compat/include "$subpkgdir"/usr/glibc-compat
}

에서 APKBUILD의 파일.

이것을 조사한 결과 최종 컨테이너에 헤더를 사용하는 것이 유용하다는 것에 의문을 갖습니다. 가능한 경우 헤더를 요구하는 종속성을 작성하고 결과 패키지를 컨테이너에 설치하는 것이 중간 컨테이너를 갖는 것이 훨씬 더 유용한 것 같습니다.


흠, 이것은 나를 위해 작동하지 않았다. 에 대해 동일한 오류가 발생 xlocale.h합니다. musl-dev어쨌든 설치 된 것을 보았습니다. 그 패키지 중 하나에 필요한 것 같습니다. libc-dev내가 말할 수있는 한 설치되었습니다.
— synic

로컬로 재현 하기 위해 requirements.txt(또는 실제로 필요한 빌드를 트리거하는 관련 부분)을 공유 할 수 있습니까 matplotlib.h?
— dawud

좋아, 나는 OP에 추가했다
— synic

약간의 연구를 한 후에는 작동하는 솔루션을 제공하는 데 사소한 시간이 필요합니다. 요구 사항과 헤더 파일이없는 이유를 설명하려고했습니다. 공란을 채우기 위해 당신에게 맡깁니다. 그래도 유용하기를 바랍니다.
— dawud

2

이 의존성은 나를 위해 일했습니다 : docker run -c 'apk update && apk add g++ make subversion gcc gfortran ca-certificates python3-dev libpng-dev freetype-dev python3; ln -s /usr/include/locale.h /usr/include/xlocale.h; python3 -m pip install matplotlib'

교체 python3로 python당신은 2.7을 원하는 경우

(@Celine의 답변 외에도)

당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.