Full disclosure: I'm the author of Dockernel.
Put the following in a file called Dockerfile
, in a separate directory.
FROM python:3.7-slim-buster
RUN pip install --upgrade pip ipython ipykernel
CMD python -m ipykernel_launcher -f $DOCKERNEL_CONNECTION_FILE
Then issue the following commands:
docker build --tag my-docker-image /path/to/the/dockerfile/dir
pip install dockernel
dockernel install my-docker-image
You should now see "my-docker-image" option when creating a new notebook in Jupyter.
Manually
It is possible to do this kind of thing without much additional implementation/tooling, it just requires a bit of manual work:
- Use the following
Dockerfile
:
FROM python:3.7-slim-buster
RUN pip install --upgrade pip ipython ipykernel
Build the image using docker build --tag my-docker-image .
Create a directory for your kernelspec, e.g. ~/.local/share/jupyter/kernels/docker_test
(%APPDATA%\jupyter\kernels\docker_test
on Windows)
Put the following kernelspec into kernel.json
file in the directory you created (Windows users might need to change argv
a bit)
{
"argv": [
"/usr/bin/docker",
"run",
"--network=host",
"-v",
"{connection_file}:/connection-spec",
"my-docker-image",
"python",
"-m",
"ipykernel_launcher",
"-f",
"/connection-spec"
],
"display_name": "docker-test",
"language": "python"
}
Jupyter should now be able spin up a container using the docker image specified above.