Skip to content

Instantly share code, notes, and snippets.

@tuxedocat
Created December 21, 2017 06:04
Show Gist options
  • Save tuxedocat/67ec1c7fc0ce0af61d6a9f32d64b08cb to your computer and use it in GitHub Desktop.
Save tuxedocat/67ec1c7fc0ce0af61d6a9f32d64b08cb to your computer and use it in GitHub Desktop.
nvidia-docker2 + Keras
ARG cuda_version=8.0
ARG cudnn_version=6
ARG distribution=ubuntu16.04
FROM nvidia/cuda:${cuda_version}-cudnn${cudnn_version}-devel-${distribution}
RUN apt-get update && apt-get install -y \
wget \
git \
libhdf5-dev \
g++ \
graphviz \
openmpi-bin && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Conda
ARG miniconda_ver=4.3.30
ARG miniconda_md5=0b80a152332a4ce5250f3c09589c7a81
ENV CONDA_DIR /opt/conda
ENV PATH=$CONDA_DIR/bin:$PATH
RUN mkdir -p $CONDA_DIR && \
echo export PATH=$CONDA_DIR/bin:'$PATH' > /etc/profile.d/conda.sh && \
wget --quiet https://repo.continuum.io/miniconda/Miniconda3-${miniconda_ver}-Linux-x86_64.sh && \
echo "${miniconda_md5} *Miniconda3-${miniconda_ver}-Linux-x86_64.sh" | md5sum -c - && \
/bin/bash /Miniconda3-${miniconda_ver}-Linux-x86_64.sh -f -b -p $CONDA_DIR && \
rm Miniconda3-${miniconda_ver}-Linux-x86_64.sh
ENV NB_USER keras
ENV NB_UID 1000
RUN useradd -m -s /bin/bash -N -u $NB_UID $NB_USER && \
mkdir -p $CONDA_DIR && \
chown $NB_USER $CONDA_DIR -R && \
mkdir -p /src && \
chown $NB_USER /src
USER keras
# Basic setup with TensorFlow
ARG python_version=3.5
RUN conda install -y python=${python_version} && \
pip install --upgrade pip && \
pip install tensorflow-gpu && \
conda install \
Pillow \
scikit-learn \
notebook \
pandas \
matplotlib \
mkl \
nose \
pyyaml \
six \
h5py && \
pip install sklearn_pandas && \
git clone https://github.com/keras-team/keras.git /src && pip install -e /src[tests] && \
pip install git+https://github.com/keras-team/keras.git && \
conda clean -yt
# Theano
ENV PATH $CONDA_DIR/bin:$PATH
RUN conda install theano pygpu bcolz && \
conda clean -yt
ADD theanorc /home/keras/.theanorc
# CNTK
ARG cntk_version=2.3.1
ARG cntk_pyver=35
ENV PATH $CONDA_DIR/bin:$PATH
RUN pip install https://cntk.ai/PythonWheel/GPU/cntk-${cntk_version}-cp${cntk_pyver}-cp${cntk_pyver}m-linux_x86_64.whl
ENV PYTHONPATH='/src/:$PYTHONPATH'
WORKDIR /src
EXPOSE 8888
CMD jupyter notebook --port=8888 --ip=0.0.0.0
help:
@cat Makefile
NAME=keras
DATA?="${HOME}/container-shared"
GPU?=0
DOCKER_FILE=Dockerfile
DOCKER=GPU=$(GPU) docker
NVRUNTIME=--runtime=nvidia
BACKEND=tensorflow
PYTHON_VERSION?=3.5
CUDA_VERSION?=8.0
CUDNN_VERSION?=6
TEST=tests/
SRC?=$(shell dirname `pwd`)
build:
docker build \
-t $(NAME):latest \
--build-arg python_version=$(PYTHON_VERSION) \
--build-arg cuda_version=$(CUDA_VERSION) \
--build-arg cudnn_version=$(CUDNN_VERSION) \
--build-arg https_proxy=$$HTTP_PROXY --build-arg http_proxy=$$HTTP_PROXY \
--build-arg HTTP_PROXY=$$HTTP_PROXY --build-arg HTTPS_PROXY=$$HTTP_PROXY \
--build-arg NO_PROXY=$$NO_PROXY --build-arg no_proxy=$$NO_PROXY \
-f $(DOCKER_FILE) .
bash:
$(DOCKER) run $(NVRUNTIME) -it \
-v $(SRC):/src/workspace -v $(DATA):/data \
-v /etc/localtime:/etc/localtime:ro \
--env KERAS_BACKEND=$(BACKEND) \
--env http_proxy=$$HTTP_PROXY \
--env https_proxy=$$HTTPS_PROXY \
--env no_proxy=$$NO_PROXY \
--env HTTP_PROXY=$$HTTP_PROXY \
--env HTTPS_PROXY=$$HTTPS_PROXY \
--env NO_PROXY=$$NO_PROXY \
$(NAME) bash
ipython:
$(DOCKER) run $(NVRUNTIME) -it \
-v $(SRC):/src/workspace -v $(DATA):/data \
-v /etc/localtime:/etc/localtime:ro \
--env KERAS_BACKEND=$(BACKEND) \
--env http_proxy=$$HTTP_PROXY \
--env https_proxy=$$HTTPS_PROXY \
--env no_proxy=$$NO_PROXY \
--env HTTP_PROXY=$$HTTP_PROXY \
--env HTTPS_PROXY=$$HTTPS_PROXY \
--env NO_PROXY=$$NO_PROXY \
$(NAME) ipython
notebook:
$(DOCKER) run $(NVRUNTIME) -it \
-v $(SRC):/src/workspace -v $(DATA):/data --net=host \
-v /etc/localtime:/etc/localtime:ro \
--env KERAS_BACKEND=$(BACKEND) \
--env http_proxy=$$HTTP_PROXY \
--env https_proxy=$$HTTPS_PROXY \
--env no_proxy=$$NO_PROXY \
--env HTTP_PROXY=$$HTTP_PROXY \
--env HTTPS_PROXY=$$HTTPS_PROXY \
--env NO_PROXY=$$NO_PROXY \
$(NAME)
test:
$(DOCKER) run $(NVRUNTIME) -it \
-v $(SRC):/src/workspace -v $(DATA):/data \
-v /etc/localtime:/etc/localtime:ro \
--env KERAS_BACKEND=$(BACKEND) keras \
--env http_proxy=$$HTTP_PROXY \
--env https_proxy=$$HTTPS_PROXY \
--env no_proxy=$$NO_PROXY \
--env HTTP_PROXY=$$HTTP_PROXY \
--env HTTPS_PROXY=$$HTTPS_PROXY \
--env NO_PROXY=$$NO_PROXY \
py.test $(TEST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment