How to run the S4TF kernel in a Docker container connected to your local (non-Docker) Jupyter instance

Without building a S4TF toolchain locally, the current choices for using Swift in Jupyter are either to use Colab or to run the swift-jupyter Docker container and work in the provided Jupyter instance.

I realized recently that Jupyter Kernel Gateway could be used to allow running the Swift kernel in a Docker container (on the Ubuntu image provided by the S4TF team) while connecting to a separate Jupyter Notebook instance (not running on the same container).

So I created a Dockerfile that builds on the base S4TF image, installs jupyter kernelgateway, and runs it on container startup.

To use it, follow the instructions in the readme. In summary:

  1. Build both images:
    docker build -f docker/Dockerfile -t swift-jupyter .
    docker build -f kernel_gateway/Dockerfile -t swift-kg .
  2. Run the kernel gateway:
    docker run -p 9999:9999 --cap-add SYS_PTRACE swift-kg
  3. Start Jupyter in your notebook directory and point it at the kernel gateway:
    jupyter notebook --gateway-url 127.0.0.1:9999

As a side note, I also recommend using Docker Buildkit to improve your image building workflow. The simplest way to do so is to prepend DOCKER_BUILDKIT=1 to your docker build commands.

See my google/swift-jupyter pull request for more specifics.

It’s worth noting explicitly that starting Jupyter Notebook up with a gateway-url means that all the kernels it can access are coming from that kernel gateway. In the case of the swift-jupyter Docker container, that means Python 3, S4TF + Python 3, and S4TF + Python 2.7.

Comments, suggestions, etc., welcome. I hope this helps someone else with their local S4TF work!