简体   繁体   English

如何将 google colab 与运行 docker 图像的本地主机连接?

[英]How to connect google colab with localhost running docker image?

Errors while connecting with localhost link连接本地主机链接时出错

I am trying to run meilisearch in colab.我正在尝试在 colab 中运行 meilisearch。 I run meiliSearch in docker and I have a localhost link http://localhost:7700/ .我在 docker 运行 meiliSearch,我有一个本地主机链接http://localhost:7700/ I have tried both http://localhost:7700/ as well as http://192.168.43.57:7700 .我已经尝试了http://localhost:7700/以及http://192.168.43.57:7700 But I am getting error.但我收到错误。 Although I can connect with my local jupyter notebook.虽然我可以连接到我本地的 jupyter notebook。 Any solution?任何解决方案?

I can't see the full screen but most likely the error in colab is because it is hosted on remote server by Google research where as the http://localhost:7700/ is on your local system.我看不到全屏,但 colab 中的错误很可能是因为它由 Google 研究托管在远程服务器上,因为 http://localhost:7700/ 在您的本地系统上。

You can't connect them using http://localhost:7700/.您无法使用 http://localhost:7700/ 连接它们。 And if you have also used your machines ip address, that is http://192.168.43.57:7700 and can't connect then did you first expose your port number 7700 to internet?如果您还使用过您的机器 ip 地址,即http://192.168.43.57:7700并且无法连接,那么您是否首先将端口号 7700 暴露给互联网?

You will need to expose your local machine and some ports(7700) using different services which provide the required.您将需要使用提供所需的不同服务来公开您的本地计算机和一些端口(7700)。

You can read the following article on how to setup tunneling service or ssh to expose the local development on internet.您可以阅读以下有关如何设置隧道服务或 ssh 的文章以在 Internet 上公开本地开发。

Medium Article on How to expose a local development server to the Internet 关于如何将本地开发服务器公开到 Internet 的中型文章

Or use this directly.或者直接使用这个。 Use local tunnel使用本地隧道

Please Follow below steps to connect docker image as a local runtime for Google-colab:请按照以下步骤将 docker 图像连接为 Google-colab 的本地运行时:

  1. Create a Dockerfile and paste the below contents创建一个Dockerfile并粘贴以下内容

 # Jupyter data science image including all packages, you may change the image as per your requirements FROM jupyter/datascience-notebook:latest # Colab step 1 RUN pip install jupyter_http_over_ws \ && jupyter serverextension enable --py jupyter_http_over_ws # Expose the port for host.network EXPOSE 8888 # Colab step 2 CMD ["jupyter","notebook","--NotebookApp.allow_origin='https://colab.research.google.com'","--allow-root","--port","8888","--NotebookApp.port_retries=0","--ip","0.0.0.0"]

  1. Build the colab-runtime image by running the command in the terminal from the same directory where Dockerfile is saved通过在终端中从保存Dockerfile的同一目录运行命令来构建colab-runtime图像

 docker build -t colab-runtime.

An Image colab-runtime:latest will be created.将创建一个图像colab-runtime:latest

  1. Fire the command in terminal to run image as a container在终端中触发命令以将图像作为容器运行

    Note:- Replace {your_host_path} with your host system path.注意:- 将 {your_host_path} 替换为您的主机系统路径。 eg /home/mujassim/work:/home/jovyan/work例如/home/mujassim/work:/home/jovyan/work

  • Do not change /home/jovyan/work path.不要更改 /home/jovyan/work 路径。

 docker run -it -p 8888:8888 -v {your_host_path}:/home/jovyan/work colab-runtime:latest

After Running the above command, A URL is provided by the container in the logs.运行上述命令后,容器在日志中提供了一个 URL。

  1. Paste that URL in colab runtime by replacing only 127.0.0.1 or container_id with localhost通过仅将127.0.0.1container_id替换为localhost ,将 URL 粘贴到 colab 运行时

  2. If you dont want to run step no.如果您不想运行步骤号。 3 again and again to start the jupyter server then follow the commands listed below: 3 一次又一次地启动 jupyter 服务器,然后按照下面列出的命令进行操作:

    • Note down the container id and name of currently running jupyter server by: docker container ls通过以下方式记下当前运行的 jupyter 服务器的容器 ID名称docker container ls
    • Stop the container for a while: docker container stop {container_id}停容器一会: docker container stop {container_id}
    • Rename the container: docker rename {old_container_name} colab-runtime重命名容器: docker 重命名 {old_container_name} colab-runtime
    • Now you may run the following commands to start or stop the local runtime for google-colab: docker container start colab-runtime or docker container stop colab-runtime现在您可以运行以下命令来启动或停止 google-colab 的本地运行时: docker container start colab-runtimedocker container stop colab-runtime

Note: You have to provide new URL each time in google colab.注意:您必须每次在 google colab 中提供新的 URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM