Advertisement
Guest User

Dockerfile for generic ML environment

a guest
Dec 21st, 2020
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.19 KB | None | 0 0
  1. FROM nvidia/cuda:10.2-base
  2.  
  3. RUN apt-get update && \
  4.     apt-get install -y --no-install-recommends git
  5.  
  6. SHELL ["/bin/bash", "-c"]
  7.  
  8. #setup miniconda
  9. ENV CONDAROOT "/opt/conda"
  10.  
  11. WORKDIR /root/
  12. ADD https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh /root/
  13.  
  14. RUN mkdir ~/.conda && \
  15.     bash Miniconda3-latest-Linux-x86_64.sh -b -p $CONDAROOT && \
  16.     #rm -rf Miniconda3-latest-Linux-x86_64.sh && \
  17.     ln -s $CONDAROOT/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
  18.     source $CONDAROOT/etc/profile.d/conda.sh
  19.  
  20. # add conda to path
  21. ENV PATH $CONDAROOT/bin:$PATH
  22.  
  23. # install conda packages, -c are channels for dependencies, -n are virtual env
  24. RUN conda update -n base -c defaults conda && \
  25.     conda create -n torch -y python=3.7 && \
  26.     conda install -n torch pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch && \
  27.     conda install -n torch -c fastai -c pytorch fastai && \
  28.     conda install -n torch -c conda-forge imageio matplotlib seaborn pandas jupyter jupyterlab scikit-image scikit-learn tqdm jupyter_contrib_nbextensions tensorboard grpcio && \
  29. #explicit nodejs version needed
  30.     conda install -n torch -c conda-forge nodejs=10.13 && \
  31. #issue:
  32. #python graphviz has errors if you don't include certain X server libraries not marked as dependencies
  33. #error is "cannot find libgvplugin_pango.so.6 or one of its dependencies try ldd"
  34. #goto directory with libgvplugin_pango.so.6 and ldd the file, ensure no dependencies are missing
  35.     conda install -n torch -c conda-forge python-graphviz xorg-libxrender xorg-libxpm xorg-libxau
  36.  
  37. # see about adding optimized pillow at some later time
  38.  
  39. # activate torch environment to install packages that are outdated or not available through conda
  40. ENV PATH $CONDAROOT/envs/torch/bin:$PATH
  41. RUN echo "source activate torch" >> ~/.bashrc && \
  42.     source activate torch && \
  43.     pip install opencv-python albumentations pretrainedmodels efficientnet-pytorch torchsummary future absl-py jupyter-tensorboard hiddenlayer && \
  44.     pip install --no-dependencies git+https://github.com/qubvel/segmentation_models.pytorch
  45.  
  46. #configure jupyter-lab to run in the docker image as root with bash as terminal and no password
  47. # notebook directory is /opt/notebooks ==> this should be your mount point
  48. RUN jupyter-lab --generate-config
  49.  
  50. RUN sed -i '/c.NotebookApp.notebook_dir/c\c.NotebookApp.notebook_dir = "'"/opt/notebooks"'"' ~/.jupyter/jupyter_notebook_config.py && \
  51.     sed -i '/c.NotebookApp.open_browser/c\c.NotebookApp.open_browser = False' ~/.jupyter/jupyter_notebook_config.py && \
  52.     sed -i '/c.NotebookApp.quit_button/c\c.NotebookApp.quit_button = True' ~/.jupyter/jupyter_notebook_config.py && \
  53.     sed -i '/c.NotebookApp.token/c\c.NotebookApp.token = "'""'"' ~/.jupyter/jupyter_notebook_config.py && \
  54.     sed -i '/c.NotebookApp.ip/c\c.NotebookApp.ip = "'"0.0.0.0"'"' ~/.jupyter/jupyter_notebook_config.py && \
  55.     sed -i '/c.NotebookApp.terminado_settings/c\c.NotebookApp.terminado_settings = {"'"shell_command"'":["'"bash"'"]}' ~/.jupyter/jupyter_notebook_config.py && \
  56.     sed -i '/c.NotebookApp.allow_root/c\c.NotebookApp.allow_root = True' ~/.jupyter/jupyter_notebook_config.py && \
  57.     jupyter labextension install @jupyter-widgets/jupyterlab-manager && \
  58.     jupyter labextension install jupyterlab_tensorboard && \
  59.     mkdir /opt/notebooks
  60. WORKDIR /opt/notebooks
  61.  
  62. # Set the random seed and copy the utility scripts to the image
  63. ENV RANDOM_SEED 2019
  64. COPY torchtest.py seed.py /opt/scripts/
  65.  
  66. # this script runs seed.py whenever an ipython kernel/console is started
  67. # this actually creates a dir in /opt/notebooks/'~'/.ipython
  68. COPY ipython_config.py ~/.ipython/profile_default/
  69.  
  70. RUN mkdir /opt/cache && \
  71.     pip freeze > ~/requirements.txt && \
  72.     conda list -n torch --export --json > ~/requirements.json
  73. ENV TORCH_HOME ~/cache/torch
  74. ENV FASTAI_HOME ~/cache/fastai
  75. ENV HOME /root/
  76.  
  77. RUN conda install -c fastai -c pytorch fastbook
  78.  
  79. # Make port 8888 available to the world outside this container [doesn't work, use docker run option -p 8888:8888]
  80. EXPOSE 8888
  81.  
  82. # Run the torchtest script when the container launches (and no other command is given)
  83. #CMD ["ipython", "/opt/scripts/torchtest.py"]
  84. CMD ["/bin/bash", "-c", "jupyter lab"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement