Created
October 25, 2017 18:45
-
-
Save mzaglia/ea8b6f824be7d8da9663806e26b75f1e to your computer and use it in GitHub Desktop.
Installing Docker, JupyterHub and creating a custom Jupyter Notebook Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###### DOCKER ###### | |
# Remove old version of docker | |
sudo apt-get remove docker docker-engine docker.io | |
# Allow apt install from HTTPS | |
sudo apt-get update && \ | |
sudo apt-get install \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
software-properties-common | |
# Add repository key | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && \ | |
sudo add-apt-repository \ | |
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \ | |
$(lsb_release -cs) \ | |
stable" | |
# Installing docker CE | |
sudo apt-get update && \ | |
sudo apt-get install docker-ce | |
# To use docker as non sudo | |
sudo groupadd docker && \ | |
sudo usermod -aG docker $USER | |
# Log out and Log back so that the changes take effect | |
## Installing docker-compose | |
## Check https://github.com/docker/compose/releases/latest to see the latest release version | |
sudo curl -o /usr/local/bin/docker-compose -L "https://github.com/docker/compose/releases/download/1.16.1/docker-compose-$(uname -s)-$(uname -m)" | |
sudo chmod +x /usr/local/bin/docker-compose | |
####### JUPYTERHUB ####### | |
### Clonning JupyterHub Docker | |
sudo apt-get update && \ | |
sudo apt-get install git | |
mkdir jupyterhub && \ | |
cd jupyterhub | |
git clone https://github.com/jupyterhub/jupyterhub-deploy-docker.git . | |
## Creating a self signed certificate: | |
mkdir secrets && \ | |
cd secrects | |
openssl req -x509 -newkey rsa:4096 -keyout jupyterhub.key -out jupyterhub.crt -days 365 -nodes -subj '/CN=localhost' | |
## Configuring your OAuth authentication | |
cat > oauth.env >> EOF | |
GITHUB_CLIENT_ID=<github_client_id> | |
GITHUB_CLIENT_SECRET=<github_client_secret> | |
OAUTH_CALLBACK_URL=https://<myhost.mydomain>/hub/oauth_callback | |
EOF | |
## Edit the oauth.env file and add your info | |
## Go to https://github.com/settings/developers to create an OAuth app, there you will receive a client ID and a client SECRET | |
cd.. | |
## Next create a file userlist with GitHub usernames, the file needs at least one admin. See the example below | |
## | |
## foo admin | |
## bar | |
## foobar | |
## To create the JupyterHub type | |
make build | |
## To use the default notebook image: | |
make notebook_image | |
## Now you should be able to run your docker compose | |
docker-compose up -d | |
## To access your JupyterHub go to https://localhost | |
####### CUSTOM JUPYTER IMAGE ####### | |
## If you want to create a custom image, you can Create a Dockerfile using a jupyter image from https://hub.docker.com/r/jupyter/ | |
## Building your custom image | |
docker build -t my-image | |
## Using your custom image | |
export DOCKER_NOTEBOOK_IMAGE=my-image | |
## or edit the docker-compose.yml file | |
# Bring down the JupyterHub container, if running | |
docker-compose down | |
# Bring it back up | |
docker-compose up -d | |
## Adding a new env to your custom image: | |
## Here is an example of a custom image with a Python 2.7 enviroment with some additional packages | |
FROM jupyter/minimal-notebook | |
USER $NB_USER | |
ENV CONDA_ENV geospatial | |
RUN conda create --yes --name $CONDA_ENV python=2.7 | |
ENV PATH /opt/conda/envs/$CONDA_ENV/bin:$PATH | |
ENV CONDA_DEFAULT_ENV $CONDA_ENV | |
ENV CONDA_PREFIX /opt/conda/envs/$CONDA_ENV | |
RUN conda install --yes ipykernel nb_conda matplotlib scipy && \ | |
conda install --yes -c conda-forge geopandas gdal && \ | |
fix-permissions $CONDA_DIR && \ | |
python -m ipykernel install --user --name geospatial --display-name "Python [geospatial]" | |
RUN cd /tmp && \ | |
git clone https://github.com/PAIR-code/facets.git && \ | |
cd facets && \ | |
jupyter nbextension install facets-dist/ --sys-prefix && \ | |
rm -rf facets && \ | |
fix-permissions $CONDA_DIR | |
# Import matplotlib the first time to build the font cache. | |
ENV XDG_CACHE_HOME /home/$NB_USER/.cache/ | |
RUN MPLBACKEND=Agg python -c "import matplotlib.pyplot" && \ | |
fix-permissions /home/$NB_USER | |
USER $NB_USER | |
### For more information see: https://github.com/jupyterhub/jupyterhub-deploy-docker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment