blz*_*blz 2 python linux docker pyenv alpine-linux
我正在尝试构建一个gliderlabs/alpine:latest仅包含pyenv及其依赖关系的docker镜像.我希望这个容器能够通过pyenv安装和执行任意解释器.
我从以下Dockerfile开始:
FROM gliderlabs/alpine:latest
RUN apk-install curl \
ca-certificates \
bash \
git \
openssl-dev \
readline-dev \
bzip2-dev \
sqlite-dev \
build-base
RUN curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer -o /pyenv-installer
RUN touch /root/.bashrc && \
/bin/ln -s /root/.bashrc /root/.bash_profile && \
/bin/bash /pyenv-installer && \
rm /pyenv-installer && \
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile && \
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile && \
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
ENV HOME /root
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
Run Code Online (Sandbox Code Playgroud)
构建完成后,我可以启动一个容器并运行bash,并且pyenv命令可用,正如预期的那样.
但是,当我尝试运行时,pyenv install 3.4.3我收到以下错误:
bash-4.3# pyenv install 3.4.3
Downloading Python-3.4.3.tgz...
-> https://yyuu.github.io/pythons/4281ff86778db65892c05151d5de738d
Installing Python-3.4.3...
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
Please consult to the Wiki page to fix the problem.
https://github.com/yyuu/pyenv/wiki/Common-build-problems
BUILD FAILED (Alpine Linux 3.2.3 using python-build 20151006)
Inspect or clean up the working tree at /tmp/python-build.20151006155321.99
Results logged to /tmp/python-build.20151006155321.99.log
Last 10 log lines:
(cd /root/.pyenv/versions/3.4.3/share/man/man1; ln -s python3.4.1 python3.1)
if test "xupgrade" != "xno" ; then \
case upgrade in \
upgrade) ensurepip="--upgrade" ;; \
install|*) ensurepip="" ;; \
esac; \
./python -E -m ensurepip \
$ensurepip --root=/ ; \
fi
Ignoring ensurepip failure: pip 6.0.8 requires SSL/TLS
Run Code Online (Sandbox Code Playgroud)
经过一段谷歌搜索后,我找到了这个页面,对于OSX/homebrew,它提出了以下修复:
CFLAGS="-I$(brew --prefix openssl)/include"
LDFLAGS="-L$(brew --prefix openssl)/lib"
Run Code Online (Sandbox Code Playgroud)
由于我没有使用OSX或Homebrew,我尝试通过在Dockerfile中添加以下行来将这些命令调整到Alpine环境:
ENV CFLAGS '-I/usr/include'
ENV LDFLAGS '-L/usr/lib'
Run Code Online (Sandbox Code Playgroud)
请注意,/usr/lib其中包含:
libssl.alibssl.solibssl.so.1.0.0并/usr/include包含openssl.这已经说过,修改似乎对我在安装Python 3.4.3时的错误没有影响.
如何让pyenv在dockerized Alpine Linux下安装python环境?
sockaddr_can类型未定义.我正式迷路了.这是一个musl错误吗?问题与musl未找到通用linux头文件有关.解决方案是安装linux-headers.
下面是一个最小的工作Dockerfile:
FROM gliderlabs/alpine:latest
RUN apk-install curl \
ca-certificates \
bash \
git \
openssl-dev \
readline-dev \
bzip2-dev \
sqlite-dev \
ncurses-dev \
linux-headers \
build-base
RUN curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer -o /pyenv-installer && \
touch /root/.bashrc && \
/bin/ln -s /root/.bashrc /root/.bash_profile && \
/bin/bash /pyenv-installer && \
rm /pyenv-installer && \
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile && \
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile && \
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
ENV HOME /root
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
Run Code Online (Sandbox Code Playgroud)