Skip to content

Instantly share code, notes, and snippets.

@pvergain
Last active November 18, 2020 23:31
Show Gist options
  • Save pvergain/6c45d0859c10ca2341512c69d46167b2 to your computer and use it in GitHub Desktop.
Save pvergain/6c45d0859c10ca2341512c69d46167b2 to your computer and use it in GitHub Desktop.
Dockerfile based on centos:7 Python3.6 and pipenv
# Use an official centos7 image
FROM centos:7
RUN localedef -i fr_FR -c -f UTF-8 -A /usr/share/locale/locale.alias fr_FR.UTF-8
ENV LANG fr_FR.utf8
# gcc because we need regex and pyldap
# openldap-devel because we need pyldap
RUN yum update -y \
&& yum install -y https://centos7.iuscommunity.org/ius-release.rpm \
&& yum install -y python36u python36u-libs python36u-devel python36u-pip \
&& yum install -y which gcc \
&& yum install -y openldap-devel
# pipenv installation
RUN pip3.6 install pipenv
RUN ln -s /usr/bin/pip3.6 /bin/pip
RUN rm /usr/bin/python
# python must be pointing to python3.6
RUN ln -s /usr/bin/python3.6 /usr/bin/python
WORKDIR /opt/intranet
# pipenv install django --python `which python3.6` --system
# pipenv install --python `which python3.6` --system
# copy the Pipfile to the working directory
COPY Pipfile /opt/intranet/
# This is useful for Docker containers, and deployment infrastructure (e.g. Heroku does this)
# explicit is better than implicit
RUN pipenv install --python `which python3.6` --system
@dashdanw
Copy link

how do you prevent ln -s /usr/bin/python3.6 /usr/bin/python from breaking yum?

@avazula
Copy link

avazula commented Jul 30, 2019

I second what Dash mentioned, removing /usr/bin/python will cause core programs to crash, including yum. Once it's broken it really is difficult to reinstall the native python version that comes with the OS installation.

@capdragon
Copy link

capdragon commented Jan 3, 2020

Works well for my purposes. Yum only needs to be working at build time. The only thing that's required to work during run time within this container is my python app.
Still I'm gonna go with this image: centos/python-36-centos7:latest

@yulintan
Copy link

Removing default python will be the pain in the ass, especially when you exec to the container for debugging purpose later

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