在docker容器内的ipyparallel / ipcluster

时间:2017-12-04 18:13:13

标签: docker ipython

我在linux主机上运行ipcluster。该设置与此SO问题(https://stackoverflow.com/a/31479269/2146052)非常相似。

我对ipcontroller_config.py

进行了以下调整
myip = '*'
c.HubFactory.engine_ip = myip
c.HubFactory.client_ip = myip
c.HubFactory.monitor_ip = myip
c.HubFactory.ip = myip

c.HubFactory.iopub = (10001, 10002)
c.HubFactory.control = (10003,10004)
c.HubFactory.task = (10005,10006)
c.HubFactory.mux = (10007,10008)
c.HubFactory.regport = 10009
c.HubFactory.hb = (10010,10011)
c.HubFactory.notifier_port = 10012

我以

启动docker容器
docker run -it --rm -p 10000-10012:10000-10012 <myimg> /bin/bash
ipcluster start -n4

ipcluster启动正常,但当我尝试连接时,我得到Hub connection timeout。如果我在docker之外运行相同的配置,则不会发生此错误。除了简单的端口转发之外,我还需要进一步调整吗?

1 个答案:

答案 0 :(得分:1)

最后是缺少的部分:

从另一个Docker容器连接时,需要在配置内指定location

c.IPControllerApp.location = '<name of service in docker-compose>'

此文档记录在https://ipyparallel.readthedocs.io/en/latest/process.html#ports-and-addresses下(有关详细信息,请参见--location部分)

还要确保两个服务都在同一个docker网络上 https://stackoverflow.com/a/38089080/2146052并查看 https://docs.docker.com/compose/networking/

ipcontroller_config.py应该看起来像这样(如果是第一次并行运行,则需要通过运行ipython profile create --parallel --profile=myprofile创建默认配置)

myip = '*'
c.HubFactory.engine_ip = myip
c.HubFactory.client_ip = myip
c.HubFactory.monitor_ip = myip
c.HubFactory.ip = myip
# c.IPControllerApp.location = '<name of service in docker-compose>'
c.IPControllerApp.location = 'ipyp'

c.HubFactory.iopub = (10001, 10002)
c.HubFactory.control = (10003,10004)
c.HubFactory.task = (10005,10006)
c.HubFactory.mux = (10007,10008)
c.HubFactory.regport = 10009
c.HubFactory.hb = (10010,10011)
c.HubFactory.notifier_port = 10012

示例docker-compose.yml设置

version: '3.3'
services:
  ipyp:
    image: "ipyp"
    build: .
    ports:
     - "10000-10012:10000-10012"
    command: ipcluster start -n2 --profile=myprofile
    volumes:
      - configdata:/root/.ipython/
    restart: always

  ipyp_test:
    image: "ipyp"
    build: .
    ports:
     - "9999:9999"
    command: jupyter lab --allow-root --port 9999 --ip=0.0.0.0
    volumes:
      -configdata:/parallelconfig:ro
    restart: always

volumes:
  configdata:

通过在ipyp_test服务中启动笔记本并运行来试用设置

import ipyparallel
fl = '/parallelconfig/profile_myprofile/security/ipcontroller-client.json'
rc = ipyparallel.Client(fl)
rc.ids