Docker:libpython2.7.so.1.0:无法打开共享对象文件:没有这样的文件或目录

时间:2018-02-09 09:03:13

标签: python docker dockerfile

Dockerfile

FROM python:2.7 as python
CMD ["bash"]

FROM ubuntu
COPY --from=python /usr/local /usr/local

然后,

docker build -t ubuntuapp .
docker run ubuntuapp /usr/local/bin/python

输出:

local/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

所以,我跑了

 docker run ubuntubr ls /usr/local/lib

输出

libpython2.7.so
libpython2.7.so.1.0
pkgconfig
python2.7

那么为什么它在/ usr / local / lib中存在时无法找到libpython2.7.so.1.0以及如何解决它?

谢谢

1 个答案:

答案 0 :(得分:0)

您需要将/ usr / local / lib添加到链接器在运行时搜索的目录列表中,然后运行ldconfig。将这两行附加到Dockerfile:

RUN echo /usr/local/lib > /etc/ld.so.conf.d/local.conf && \
    ldconfig

然后我用ubuntuapp测试它:

$ docker run --rm -it test /usr/local/bin/python
Python 2.7.14 (default, Dec 12 2017, 16:55:09) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>