Skip to content

Instantly share code, notes, and snippets.

@jprjr
Created November 26, 2013 23:09
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save jprjr/7667947 to your computer and use it in GitHub Desktop.
Save jprjr/7667947 to your computer and use it in GitHub Desktop.
Setting up pyenv in docker
FROM tianon/centos-null:5.9
RUN rpm -i http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
RUN yum -y update
RUN yum -y install gcc git curl make zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl openssl-devel
RUN useradd -m python_user
RUN ln -s /proc/self/fd /dev/fd
WORKDIR /home/python_user
USER python_user
RUN git clone git://github.com/yyuu/pyenv.git .pyenv
ENV HOME /home/python_user
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
RUN pyenv install 2.7.6
RUN pyenv global 2.7.6
RUN pyenv rehash
RUN pip install --egg scons
# Do whatever extra install things you need here...
ADD info.py /home/python_user/info.py
ENTRYPOINT ["python"]
CMD ["info.py"]
# build with something like
# docker build -t python-demo .
# to see current python version by running info.py
# docker run python-demo
# To run anything else
# docker run python-demo /path/to/python/file
#!/usr/bin/env python
import platform
import os
print platform.platform()
print platform.python_version()
print os.getuid()
@floer32
Copy link

floer32 commented Jan 17, 2017

@0xnurl
Copy link

0xnurl commented Mar 9, 2018

Thank you so much for this

@patarapolw
Copy link

My update.

FROM debian:buster-slim

RUN apt-get update
RUN apt-get install -y --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
RUN apt-get install -y mecab-ipadic-utf8

ENV HOME="/root"

WORKDIR $HOME
RUN apt-get install -y git
RUN git clone --depth=1 https://github.com/pyenv/pyenv.git .pyenv

ENV PYENV_ROOT="$HOME/.pyenv"
ENV PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"
RUN pyenv install 3.8.6
RUN pyenv global 3.8.6

@mayhs19
Copy link

mayhs19 commented Mar 29, 2021

My Update for Ubuntu:

FROM ubuntu:16.04

ENV PYTHON_VERSION 2.7.10

#Set of all dependencies needed for pyenv to work on Ubuntu
RUN apt-get update \ 
        && apt-get install -y --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget ca-certificates curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev mecab-ipadic-utf8 git

# Set-up necessary Env vars for PyEnv
ENV PYENV_ROOT /root/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH

# Install pyenv
RUN set -ex \
    && curl https://pyenv.run | bash \
    && pyenv update \
    && pyenv install $PYTHON_VERSION \
    && pyenv global $PYTHON_VERSION \
    && pyenv rehash

# Optional : Checks Pyenv version on container start-up
ENTRYPOINT [ "pyenv","version" ]

@Jeroendevr
Copy link

@mayhs19 Thanks for the ubuntu version

@vholmer
Copy link

vholmer commented Jan 18, 2023

@mayhs19 Thanks for this. Helped me out a lot!

@fengqi2010
Copy link

alpine version

FROM alpine:3.17

ARG PYTHON_VERSION=3.10

#set mirrors if you need
#RUN sed -i 's/dl-cdn.alpinelinux.org/repo.huaweicloud.com/g' /etc/apk/repositories

RUN apk update && apk add --no-cache \
    dpkg-dev dpkg gcc gdbm-dev libc-dev libffi-dev libnsl-dev libtirpc-dev  \
    make ncurses-dev openssl-dev patch util-linux-dev zlib-dev

ENV HOME="/root"

WORKDIR $HOME
RUN apk add --no-cache git bash
RUN git clone --depth=1 https://github.com/pyenv/pyenv.git .pyenv

ENV PYENV_ROOT="$HOME/.pyenv"
ENV PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"

#set mirrors if you need
#ENV PYTHON_BUILD_MIRROR_URL="https://repo.huaweicloud.com/python"
#ENV PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM=1
RUN pyenv install $PYTHON_VERSION
RUN pyenv global $PYTHON_VERSION

test 3.6 to 3.12

@earonesty
Copy link

for ubuntu 22, use the same ubuntu16, but add libncursesw5-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment