Skip to content

Instantly share code, notes, and snippets.

@fenchu
Created October 22, 2018 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fenchu/14b8fe5a0c24942f845a35106c7b176a to your computer and use it in GitHub Desktop.
Save fenchu/14b8fe5a0c24942f845a35106c7b176a to your computer and use it in GitHub Desktop.
Pyenv in docker
FROM ubuntu:16.04
MAINTAINER Morten Bjoernsvik <morten_bjoernsvik@yahoo.no>
ARG LANG=nb_NO.UTF-8
ENV LANG ${LANG}
ARG TZ=Europe/Oslo
ENV TZ ${TZ}
ARG MYHOME=/root
ENV MYHOME ${MYHOME}
ARG PYTHONVER=3.7.1
ENV PYTHONVER ${PYTHONVER}
ARG PYTHONNAME=pythontest
ENV PYTHONNAME ${PYTHONNAME}
# Add perforce
RUN echo "deb http://package.perforce.com/apt/ubuntu/ xenial release" > /etc/apt/sources.list.d/perforce.list && \
wget -qO - https://package.perforce.com/perforce.pubkey | apt-key add -
RUN apt-get update && apt-get upgrade -y && apt-get install -y locales wget git curl zip vim apt-transport-https tzdata language-pack-nb language-pack-nb-base manpages \
build-essential libjpeg-dev libssl-dev zlib1g-dev libbz2-dev libreadline-dev libreadline6-dev libsqlite3-dev tk-dev libffi-dev libpng-dev libfreetype6-dev helix-cli
RUN echo "nb_NO.UTF-8 UTF-8" > /etc/locale.gen && \
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen && \
update-locale LANG=nb_NO.UTF-8 && \
echo "LANG=nb_NO.UTF-8" > /etc/default/locale && \
echo "LC_ALL=nb_NO.UTF-8" >> /etc/default/locale
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN git clone https://github.com/pyenv/pyenv.git ${MYHOME}/.pyenv && \
git clone https://github.com/yyuu/pyenv-virtualenv.git ${MYHOME}/.pyenv/plugins/pyenv-virtualenv && \
git clone git://github.com/pyenv/pyenv-update.git ${MYHOME}/.pyenv/plugins/pyenv-update
SHELL ["/bin/bash", "-c", "-l"]
COPY ./.bash_profile /tmp/
RUN cat /tmp/.bash_profile >> ${MYHOME}/.bashrc && \
cat /tmp/.bash_profile >> ${MYHOME}/.bash_profile && \
rm -f /tmp/.bash_profile && \
source ${MYHOME}/.bash_profile && \
pyenv install ${PYTHONVER} && \
pyenv virtualenv ${PYTHONVER} ${PYTHONNAME} && \
pyenv global ${PYTHONNAME}
@fenchu
Copy link
Author

fenchu commented Oct 22, 2018

#build
This is configured for my usecase with perforce and norwegian localization but can easily be fixed

docker build -- -t python-base:3.7.1 --build-arg PYTHONVER=3.7.1 --build-arg PYTHONNAME=<your description> .

If you use this as base for your projects and use SHELL ["/bin/bash", "-c", "-l"] it will use this python version:

$ docker run -ti python-base:3.7.1 /bin/bash
(pythontest) root@bbc55db81645:/# python --version
Python 3.7.1

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