使用 Docker 快速搭建 Rust 的 Jupyter Notebook

在 Jupyter notebook 上面运行 Python 程序非常,实际上 Jupyter 也支持其他的内核。

我们可以使用 docker 运行一个已经安装好 Rust + Conda + Jupyter Notebook 的的容器。

如下:

docker run --name jupyter-rust -d -p 8899:8899 -v `pwd`:/opt/notebooks --platform=linux/amd64 davideuler/jupyter-rust:1.0

docker logs jupyter-rust

这个命令从 docker 官网拉取到 jupyter-rust:1.0 的镜像,创建容器,并且把当前目录映射到容器的 /opt/notebooks 目录,同时映射容器的端口 8899 到本地。

这里的 docker logs 命令可以看到类似如下的输出:

这里显示了访问 jupyter lab 需要的 token。 然后你可以使用这个 URL 访问 jupyter lab。 看到这样的界面:

点击上面的 Rust 图标可以创建一个 Rust 内核的 notebook,在上面可以执行 rust  代码。

notebook 会被保存到宿主机运行 启动容器的命令时所在的目录。

执行一段 rust 代码如下:

这样我们就可以方便得在浏览器上交互式地输入 Rust 代码,在浏览器上看到执行的结果。

容器的背后使用了开源项目: evcxr_jupyter, evcx_jupyter 提供了一个 Jupyter 的 Rust 语言内核。

完整的 Dockerfile 文件参考 gitbhub 上面的项目:

https://github.com/davideuler/jupyter-rust

猜你喜欢

转载自blog.csdn.net/davidullua/article/details/127941163