Building your first container
Create a notebook
In this example we are going to use a dummy notebook to show how to create reprodiucible figures.
Please bear in mind that this is only a demo you can do the same steps with other notebooks OR code.
Download the following notebook locally: Click
to Download and put it into a src folder.
Data
Download the following data locally: Click
to Download and put it into a Data Folder
Specifying the environment
Look inside the notebook and find the external libraries. Put these into a requirements.txt
file.
hvplot==0.7.0
xarray==0.16.2
In the file above we are only "freezing" the libraries we use and not their dependancies.
Be as specific as possible with the versions
Specifying the environment
This "freezes" everything in the environment even libraries that aren't used, it can cause
problems if certain packages are no longer available.
$
pip freeze > requirements.txt
$
conda list --export > spec-file.txt
$
conda env export > environment.yml
Recreating the environment
$
pip install -r requirements.txt
$
conda create --name myenv --file spec-file.txt
$
conda env create -f environment.yml
Creating the Dockerfile - Choosing the base image
FROM jupyter/scipy-notebook
Creating the Dockerfile - Copying Data
COPY Data /home/jovyan/work/data
COPY requirements.txt /home/jovyan/work/requirements.txt
COPY demo_notebook /home/jovyan/work/
Recreating the environment
$
pip install -r requirements.txt
$
conda create --name myenv --file spec-file.txt
$
conda env create -f environment.yml
Putting it all together
FROM jupyter/scipy-notebook
COPY requirements.txt /home/jovyan/work/requirements.txt
RUN pip install -r /home/jovyan/work/requirements.txt
COPY demo_notebook.ipynb /home/jovyan/work/
COPY Data /home/jovyan/work/data
Each Command is a "layer" for quick development place code that doesn't change towards the start
of the file
Building the image
$
docker build -t my-notebook .
Running the image
$
docker run -it -p 8888:8888 my-notebook
We use -it to run the container interactively
We use -p to bind the jupyter port to the host port 8888