Dockerfile for greta version 0.3.1

Hi all, took a bit to figure out some of the intricacies of making sure I was getting the correct python, tensorflow, and tf-probability version, but I’ve got a working Docker image built on rocker/geospatial:4.0.3 (of course, you could change that to a lighter rstudio base image from rocker if you prefer). Other colleagues figured out the virtual environment intricacies, and I just figured out the versioning issue for Python and Python libraries that were introduced with the release of Python 3.8

Here’s the Dockerfile in case others might be able to make use of it!

FROM rocker/geospatial:4.0.3

### Greta and tensorflow stuff
ENV WORKON_HOME /opt/virtualenvs
ENV PYTHON_VENV_PATH $WORKON_HOME/r-tensorflow

RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common && \
    add-apt-repository -y ppa:deadsnakes/ppa && \
    apt-get update && apt-get install -y python3.7-dev python3.7-venv && \
    rm -rf /var/lib/apt/lists/*

RUN python3.7 -m venv ${PYTHON_VENV_PATH}

RUN chown -R rstudio:rstudio ${WORKON_HOME}
ENV PATH ${PYTHON_VENV_PATH}/bin:${PATH}
## And set ENV for R! It doesn't read from the environment...
RUN echo "PATH=${PATH}" >> /usr/local/lib/R/etc/Renviron && \
    echo "WORKON_HOME=${WORKON_HOME}" >> /usr/local/lib/R/etc/Renviron && \
    echo "RETICULATE_PYTHON_ENV=${PYTHON_VENV_PATH}" >> /usr/local/lib/R/etc/Renviron

## Because reticulate hardwires these PATHs...
RUN ln -s ${PYTHON_VENV_PATH}/bin/pip /usr/local/bin/pip && \
    ln -s ${PYTHON_VENV_PATH}/bin/virtualenv /usr/local/bin/virtualenv

## install as user to avoid venv issues later
USER rstudio

RUN pip3 install wheel

RUN pip3 install \
    h5py==3.1.0 \
    numpy==1.19.2 \
    six==1.15.0 \
    pyyaml==3.13 \
    requests==2.21.0 \
    Pillow==5.4.1 \
    tensorflow==1.14.0 \
    tensorflow-probability==0.7.0 \
    keras==2.2.4 \
    --no-cache-dir

USER root
RUN install2.r reticulate tensorflow keras gretaFROM rocker/geospatial:4.0.3

### Greta and tensorflow stuff
ENV WORKON_HOME /opt/virtualenvs
ENV PYTHON_VENV_PATH $WORKON_HOME/r-tensorflow

RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common && \
    add-apt-repository -y ppa:deadsnakes/ppa && \
    apt-get update && apt-get install -y python3.7-dev python3.7-venv && \
    rm -rf /var/lib/apt/lists/*

RUN python3.7 -m venv ${PYTHON_VENV_PATH}

RUN chown -R rstudio:rstudio ${WORKON_HOME}
ENV PATH ${PYTHON_VENV_PATH}/bin:${PATH}
## And set ENV for R! It doesn't read from the environment...
RUN echo "PATH=${PATH}" >> /usr/local/lib/R/etc/Renviron && \
    echo "WORKON_HOME=${WORKON_HOME}" >> /usr/local/lib/R/etc/Renviron && \
    echo "RETICULATE_PYTHON_ENV=${PYTHON_VENV_PATH}" >> /usr/local/lib/R/etc/Renviron

## Because reticulate hardwires these PATHs...
RUN ln -s ${PYTHON_VENV_PATH}/bin/pip /usr/local/bin/pip && \
    ln -s ${PYTHON_VENV_PATH}/bin/virtualenv /usr/local/bin/virtualenv

## install as user to avoid venv issues later
USER rstudio

RUN pip3 install wheel

RUN pip3 install \
    h5py==3.1.0 \
    numpy==1.19.2 \
    six==1.15.0 \
    pyyaml==3.13 \
    requests==2.21.0 \
    Pillow==5.4.1 \
    tensorflow==1.14.0 \
    tensorflow-probability==0.7.0 \
    keras==2.2.4 \
    --no-cache-dir

USER root
RUN install2.r reticulate tensorflow keras greta
1 Like

Thanks so much, @vlandau!

I’ve added this to the an issue on greta - in the future there will be a list of docker files and images and some short guidance on how to set it up with say rstudio server etc.

I’ll post here when that documentation is done!

1 Like

Great! Also, a note to any looking at that Dockerfile… somehow I managed to copy and paste the text twice and can’t edit it now! Whoops!

The Dockerfile should end with:

USER root
RUN install2.r reticulate tensorflow keras greta

after the first 2 pip3 install commands

1 Like