Skip to content

Instantly share code, notes, and snippets.

@garywu
Last active February 8, 2017 05:05
Show Gist options
  • Select an option

  • Save garywu/6c01c97bcb4dd5a62d4f49abc75a412f to your computer and use it in GitHub Desktop.

Select an option

Save garywu/6c01c97bcb4dd5a62d4f49abc75a412f to your computer and use it in GitHub Desktop.
jupyter-notebook-kernel-gateway-hello-world
Jupyter notebook as microservice with kernel gateway and docker

#Minimum jupyter kernel gateway microservice Size of docker image is 500 MB

  1. clone or download the gist
  2. build the docker container
docker build -t hello-service .
  1. run docker

    docker run -p 8888:8888  hello-service
    
  2. browse to http://localhost:8888/hello

  3. you should see output:

    {
       hello: "world"
    }
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
# jupyter/base-notebook 493 MB
FROM jupyter/base-notebook
# jupyter/minimal-notebook 2 GB
# FROM jupyter/minimal-notebook
# RUN pip install --upgrade pip
# Install Kernel Gateway
RUN pip install jupyter-kernel-gateway
# Configure container startup
ENTRYPOINT ["tini", "--", "jupyter", "kernelgateway", "--KernelGatewayApp.api=notebook-http", "--KernelGatewayApp.ip=0.0.0.0", "--KernelGatewayApp.seed_uri=/srv/notebooks/hello.ipynb"]
# Add notebook served by the kernel gateway
ADD hello.ipynb /srv/notebooks/
# Run container as user jovyan
USER jovyan
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true,
"focus": false,
"id": "2fd29b94-4292-4da6-b82e-b88f0a64da61"
},
"outputs": [],
"source": [
"# GET /hello\n",
"print('{\"hello\": \"world\"}')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment