I'm trying to run jupyter console
in a Linux docker image, and connect to from the host OS (Windows). To do this, I must specify the used ports so that docker publishes them. I cannot use --network host
, since my host OS is Windows (docs). So I must know before hand which ports to publish. I have tried a few approaches, but none of them seem to work:
$ jupyter console --shell=6001 --iopub=6002 --stdin=6003 --control=6004 --hb=6005
Jupyter console 6.4.3
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %connect_info
{
"shell_port": 41847,
"iopub_port": 36575,
"stdin_port": 43621,
"control_port": 49365,
"hb_port": 41115,
"ip": "127.0.0.1",
"key": "f1c2fc92-1e1ac00bfa0797516ce51331",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
And:
$ jupyter console --generate-config
Writing default config to: /root/.jupyter/jupyter_console_config.py
$ nano /root/.jupyter/jupyter_console_config.py # Configure c.ConnectionFileMixin.control_port etc.
$ jupyter console
Jupyter console 6.4.3
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %connect_info
{
"shell_port": 40717,
"iopub_port": 49261,
"stdin_port": 46105,
"control_port": 47223,
"hb_port": 44913,
"ip": "127.0.0.1",
"key": "ee31c87f-ceb16a5b2c752085b9577677",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
Any suggestions are welcome. I must say I'm a Jupyter beginner, I'm not even quite sure what is the difference between starting a console and a notebook. My goal is to run a Spyder IDE on Windows but execute the code (via an IPython session) inside the docker container.
Edit 1: I tested this on a different machine, and interestingly the command line arguments seem to work!
$ jupyter console --shell=6001 --iopub=6002 --stdin=6003 --control=6004 --hb=6005
Jupyter console 6.4.0
Python 3.8.0 (default, Nov 6 2019, 21:49:08)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %connect_info
{
"shell_port": 6001,
"iopub_port": 6002,
"stdin_port": 6003,
"control_port": 6004,
"hb_port": 6005,
"ip": "127.0.0.1",
"key": "904874f1-cd228fd7436e99d56d83ac81",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
Is this just a bug in the older version of jupyter / ipython?
Edit 2: Using newer Python and Jupyter on Linux doesn't seem to fix this:
# jupyter --version
Selected Jupyter core packages...
IPython : 8.6.0
ipykernel : 6.17.0
ipywidgets : 8.0.2
jupyter_client : 7.3.4
jupyter_core : 4.11.2
jupyter_server : 1.23.0
jupyterlab : 3.5.0
nbclient : 0.7.0
nbconvert : 7.2.3
nbformat : 5.7.0
notebook : 6.5.2
qtconsole : 5.4.0
traitlets : 5.5.0
# jupyter console --shell=6001 --iopub=6002 --stdin=6003 --control=6004 --hb=6005
Jupyter console 6.4.4
Python 3.9.13 (main, Oct 13 2022, 21:15:33)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %connect_info
{
"shell_port": 42637,
"iopub_port": 58425,
"stdin_port": 38171,
"control_port": 54103,
"hb_port": 52349,
"ip": "127.0.0.1",
"key": "b73514a7-0a23b4918cf72d63f13a0577",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
Edit 3, yet an other test. This time on Windows:
>jupyter --version
Selected Jupyter core packages...
IPython : 8.6.0
ipykernel : 6.17.0
ipywidgets : 8.0.2
jupyter_client : 7.3.4
jupyter_core : 4.11.2
jupyter_server : 1.23.0
jupyterlab : not installed
nbclient : 0.7.0
nbconvert : 7.2.3
nbformat : 5.7.0
notebook : 6.5.2
qtconsole : 5.4.0
traitlets : 5.5.0
>jupyter console --shell=6001 --iopub=6002 --stdin=6003 --control=6004 --hb=6005
C:\vendor\Anaconda3\envs\tpa\lib\site-packages\zmq\_future.py:679: RuntimeWarning: Proactor event loop does not implement add_reader family of methods required for zmq. Registering an additional selector thread for add_reader support via tornado. Use `asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())` to avoid this warning.
self._get_loop()
Jupyter console 6.4.4
Python 3.9.13 (main, Oct 13 2022, 21:23:06) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %connect_info
{
"shell_port": 4048,
"iopub_port": 4049,
"stdin_port": 4050,
"control_port": 4052,
"hb_port": 4051,
"ip": "127.0.0.1",
"key": "463250f7-86ba2e10420dbc3869f8f2ac",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
I haven't yet figured out a pattern on when the port config is respected and when it isn't. :(