Package managing and volume best practices in jupyter with docker

Viewed 714

I'm trying to create a project template with jupyter/datascience-notebook on docker, and I'm having some confusion about:

  1. Have I to create a container (I use docker-compose) for each project?

  2. In my project template, with the Dockerfile and docker-compose.yml file, I have a folder called "notebooks", that I mounted on /home/jovyan, in order to save data when I stop container, but I have also found also some cache files, is this a best practice?

  3. How can I manage packages? I have to write in jupyter notebooks on top something like "! pip install xxxx", or in Dockerfile I have to write "RUN pip install xxxx", and "pip install" or "conda install"? both of these enviroments are recognized from jupyter? And if I have "requirements.txt", can I create a "requirements.pip.txt" for pip, and a "requirements.conda.txt" for conda? mhm..... Some best practice?

Dockerfile:

FROM jupyter/datascience-notebook:latest
EXPOSE 8888
ENV JUPYTERLAB_ENABLED=true

docker-compose.yml:

version: "3.8"
services:
  jupyter:
    build: .
    ports:
      - 8888:8888
    container_name: jupyter
    volumes:
      - ./notebooks:/home/jovyan

This is my project now [1]: https://i.stack.imgur.com/ng55d.png

1 Answers
  1. Unlikely that you would need to make more than 1 container unless you need to use conflicting modules.

  2. Mount to a different directory, e.g. /home/jovyan/notebooks, and set that as your working directory in jupyter config. It may be tricky, you may want to clone my docker-compose for simple setup: https://github.com/vladiuz1/py3-jupyter-docker-compose just edit the Dockerfile and replace minimal with datascience so your desired set is setup.

  3. Its best to mount requirements.txt with list of python packages you need. Again refer to my docker-compose to see how to do it the right way.

Related