[英]How to dockerize Jupyter lab
I'm trying to dockerize the Jupyter Lab and so I tried to create a Dockerfile
as below,我正在尝试对 Jupyter Lab进行 dockerize,因此我尝试创建一个Dockerfile
,如下所示,
FROM python:3.6
WORKDIR /jup
RUN pip install jupyter -U && pip install jupyterlab
EXPOSE 8888
ENTRYPOINT ["jupyter", "lab"]
and run the commands, docker build . -t jupyter
并运行命令docker build . -t jupyter
docker build . -t jupyter
then docker run jupyter
. docker build . -t jupyter
然后docker run jupyter
。 But unfortunately I got some error as below但不幸的是我得到了一些错误如下
[I 07:56:34.123 LabApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
Traceback (most recent call last):
File "/usr/local/bin/jupyter-lab", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/jupyter_core/application.py", line 266, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/usr/local/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/usr/local/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 1507, in initialize
self.init_webapp()
File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 1297, in init_webapp
self.http_server.listen(port, self.ip)
File "/usr/local/lib/python3.6/site-packages/tornado/tcpserver.py", line 142, in listen
sockets = bind_sockets(port, address=address)
File "/usr/local/lib/python3.6/site-packages/tornado/netutil.py", line 197, in bind_sockets
sock.bind(sockaddr)
OSError: [Errno 99] Cannot assign requested address
How can I dockerize jupyter lab
?我怎样才能dockerize jupyter lab
? [ by solving this error ] [通过解决这个错误]
When you start jupyter lab
you should define --ip
parameter. 当您启动jupyter lab
应定义--ip
参数。 For example, --ip=0.0.0.0
. 例如, - --ip=0.0.0.0
。
After this you will have another error: 在此之后,您将有另一个错误:
[C 08:14:56.973 LabApp] Running as root is not recommended. Use --allow-root to bypass.
So, if you want to proceed you need to add --allow-root
as well. 因此,如果您想继续,还需要添加--allow-root
。
The final Dockerfile
is: 最终的Dockerfile
是:
FROM python:3.6
WORKDIR /jup
RUN pip install jupyter -U && pip install jupyterlab
EXPOSE 8888
ENTRYPOINT ["jupyter", "lab","--ip=0.0.0.0","--allow-root"]
Whilst searching around I came across this question, before going on to discover a reference to Jupyter Labs in the 'Read The Docs' pages for Jupyter Docker Stacks (see here ). 在搜索时我遇到了这个问题,然后在Jupyter Docker Stacks的“Read The Docs”页面中发现了对Jupyter Labs的引用(见这里 )。 The documentation says: 文件说:
JupyterLab is preinstalled as a notebook extension starting in tag c33a7dc0eece. JupyterLab从标签c33a7dc0eece开始预装为笔记本扩展。
and they suggest using a command like: 他们建议使用如下命令:
docker run -it --rm -p 8888:8888 jupyter/datascience-notebook start.sh jupyter lab
I thought I might as well add the reference here in case it's useful for others. 我想我也可以在这里添加引用,以防它对其他人有用。 (It's not immediately obvious on Docker Hub for example, that there is support for Jupyter Labs.) (例如,在Docker Hub上并没有立即显示出对Jupyter Labs的支持。)
As an alternative to building your own Docker image with JupyterLab, you can also use the ML Workspace image.作为使用 JupyterLab 构建您自己的 Docker 映像的替代方法,您还可以使用ML Workspace映像。 The ML Workspace is an open-source web IDE that combines Jupyter, JupyterLab, VS Code, and many other tools & libraries into one convenient Docker image. ML Workspace 是一种开源 Web IDE,它将 Jupyter、JupyterLab、VS Code 以及许多其他工具和库组合到一个方便的 Docker 映像中。 Deploying a single workspace instance is as simple as:部署单个工作区实例非常简单:
docker run -p 8080:8080 mltooling/ml-workspace:latest
All tools are accessible from the same port and integrated into the Jupyter UI.所有工具都可以从同一个端口访问并集成到 Jupyter UI 中。 You can find further information on how to access JupyterLab here .您可以在此处找到有关如何访问 JupyterLab 的更多信息。
either run 要么跑
docker run jupyter --allow-root --ip=0.0.0.0 --port=8888
or change ENTRYPOINT
as docker run jupyter --allow-root --ip=0.0.0.0 --port=8888
或将ENTRYPOINT
更改为
ENTRYPOINT ["jupyter", "lab", "--allow-root","--ip=0.0.0.0", "--no-browser"]
You really don't have to roll your own.你真的不必自己动手。 The Jupyter Docker Stack provides ready-made JupyterLab images that work together with a JupyterHub docker image. Jupyter Docker Stack提供现成的 JupyterLab 图像,可与 JupyterHub docker 图像一起使用。 The Hub can "spawn" a separate container for each user running a given JupyterLab (search for the DockerSpawner
class that's responsible for the magic). Hub 可以为运行给定 JupyterLab 的每个用户“生成”一个单独的容器(搜索负责魔术的DockerSpawner
类)。
The reason I am adding this as a separate answer is the CAVEAT : while useful links are available on the Internet, they are often outdated and there are inconsistencies between the documentation and reality that make the "productive Dockerisation of Jupyter" rather painful.我将此作为单独的答案添加的原因是CAVEAT :虽然互联网上提供了有用的链接,但它们通常已经过时,并且文档和现实之间存在不一致,这使得“Jupyter 的生产性 Dockerisation”相当痛苦。 Just to name a few that I encountered:仅举几个我遇到的:
jovyan
, UID=1000.有一个关于用户日志到Jupyter枢纽身份VS在Jupyter实验室容器实际运行用户的身份很多的困惑:后者总是jovyan
,UID = 1000。 This can lead to unexpected surprises regarding file ownerships and permissions.这可能会导致有关文件所有权和权限的意外意外。.sh
extension because then it's meant to do something different...例如,复制脚本不能有.sh
扩展名,因为它意味着做一些不同的事情......YMMV, of course. YMMV,当然。 And despite all this, when it works then it's a rather elegant setup.尽管如此,当它工作时,它是一个相当优雅的设置。 I am going to try it out for real on some unlucky students soon :-)我很快就会在一些不幸的学生身上进行真实的尝试:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.