Repository: jupyter/docker-stacks

Issue:
Consider not writing in user home
All the images (starting from base notebook) write part of the configuration inside the user home folder, and assume that `/home/$NB_USER/work` will be mounted. This has a practical limitation that it is not easy to setup a hub such that useful folders like `.ssh`, or e.g. `.bash_history` persist across container restarts.

I might be missing underlying assumptions and use cases, but I suggest to assume that home itself would be mounted, and instead modify the global configuration options.


Discussion:
You make a good point. We've been slowly moving config files out of home and either into the sys-prefix or root prefix over time. It looks like the remaining files of significance in the user's home directory are:

```
.local/share/jupyter/jupyter_notebook_config.py
.ipython/profile_default/startup/mplimporthook.py
.conda/environments.txt
```

I know the first can move into the conda prefix /opt/conda/etc/jupyter. I think the second can as well. I have seen any negative consequences of simply deleting or ignoring the third, but I also haven't experimented or researched it much beyond running `conda env list`.

Are you referring to a specific derivative dockerfile? In `base-notebook` I only see `.bash_logout  .bashrc  .continuum  .curlrc  .jupyter  .profile  work` in home, and `.continuum` is empty.
I see now, it's in `scipy-notebook`. I might be confusing something, but I don't understand the role of this file:

```bash
docker run -it --rm jupyter/scipy-notebook bash
jovyan@9d2aacb3af29:~/work$ more ~/.conda/environments.txt
/opt/conda/envs/python2
jovyan@9d2aacb3af29:~/work$ rm -rf ~/.conda
jovyan@9d2aacb3af29:~/work$ conda env list
# conda environments:
#
python2                  /opt/conda/envs/python2
root                  *  /opt/conda
```
@akhmerov I don't know the role of the file either. It could be harmless to remove it. https://github.com/conda/conda/issues/945 seems to have a bit of info about it.
We're using an image without that file for a long time already. It appears it is indeed harmless to remove.
This also means that you can't use this in KubeSpawner with Persistent storage, and I don't want to encourage the default to attach persistent storage somewhere other than $HOME. https://github.com/jupyterhub/kubespawner/issues/31 is related.

Resolving patch:
diff --git a/scipy-notebook/mplimporthook.py b/scipy-notebook/mplimporthook.py
deleted file mode 100644
--- a/scipy-notebook/mplimporthook.py
+++ /dev/null
@@ -1,55 +0,0 @@
-"""Startup script for IPython kernel.
-
-Installs an import hook to configure the matplotlib backend on the fly.
-
-Originally from @minrk at 
-https://github.com/minrk/profile_default/blob/master/startup/mplimporthook.py
-Repurposed for docker-stacks to address repeat bugs like
-https://github.com/jupyter/docker-stacks/issues/235.
-"""
-import sys
-from IPython import get_ipython
-
-class MatplotlibFinder(object):
-    """Import hook that notices when matplotlib.pyplot or pylab is imported
-    and tries to configure the matplotlib backend appropriately for the
-    environment.
-    """
-    _called = False
-    
-    def find_module(self, fullname, path=None):
-        if self._called:
-            # already handled
-            return
-        
-        if fullname not in ('pylab', 'matplotlib.pyplot'):
-            # not matplotlib
-            return
-        
-        # don't call me again
-        self._called = True
-        
-        try:
-            # remove myself from the import hooks
-            sys.meta_path = [loader for loader in sys.meta_path if loader is not self]
-        except ValueError:
-            pass
-        
-        ip = get_ipython()
-        if ip is None:
-            # not in an interactive environment
-            return
-            
-        if ip.pylab_gui_select:
-            # backend already selected
-            return
-            
-        if hasattr(ip, 'kernel'):
-            # default to inline in kernel environments
-            ip.enable_matplotlib('inline')
-        else:
-            print('enabling matplotlib')
-            ip.enable_matplotlib()
-
-# install the finder immediately
-sys.meta_path.insert(0, MatplotlibFinder())
\ No newline at end of file


Test patch: