4

I'm trying to build a docker image from gliderlabs/alpine:latest containing only pyenv and it's dependencies. I would like for this container to be able to install and execute an arbitrary interpreter through pyenv.

Initial Attempt

I began with the following 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

The Error

Once built, I can start a container and run bash, and the pyenv command is available, as expected.

However, when I try to run pyenv install 3.4.3 I get the following error:

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

Attempted Fix

After a bit of googling I found this page, which, for OSX/homebrew, suggests the following fix:

CFLAGS="-I$(brew --prefix openssl)/include"
LDFLAGS="-L$(brew --prefix openssl)/lib"

Since I'm not using OSX or Homebrew, I attempted to adapt these commands to an Alpine environment by adding the following lines to the Dockerfile:

ENV CFLAGS '-I/usr/include'
ENV LDFLAGS '-L/usr/lib'

Please note that /usr/lib contains:

  • libssl.a
  • libssl.so
  • libssl.so.1.0.0

and /usr/include contains openssl. This having been said, the modification seems to have no impact on my error when installing Python 3.4.3.

The Question

How can I get pyenv to install a python environment under a dockerized Alpine Linux?

Edit:

  1. The pyenv build log is apparently chocking because the sockaddr_can type is undefined. I'm officially lost. Is this a musl bug ?
4

2 回答 2

5

问题与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
于 2015-10-06T17:14:17.543 回答
4

我猜这里的问题是你没有标题,你需要安装它们。
只需添加apk add openssl-dev到您的 Dockerfile。

尝试在您的容器中运行 pyenv doctor 并查看是否安装了所有必需的依赖项。
另请参阅https://github.com/yyuu/pyenv/wiki/Common-build-problems#requirements以获取所需的软件包,并尝试为 Alpine Linux 找到正确的等效项。当您使用它时,将它们添加到文档中,以便其他人能够找到它。

于 2015-10-06T15:39:58.403 回答