-
-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connecting to kernel in a Docker image #481
Comments
I am not sure how to make the exact existing workflow work. I remember having trouble passing the port information using the jupyter command, so this looks more of a jupyter issue. If you login to your docker you will see a As a workaround, I ended up invoking ipython in the remote machine. The following workaround requires an ssh server in your docker. ssh is being used to tunnel your python session. One way to make the kernel respect the predefined ports is creating a custom {
"shell_port": 38363,
"iopub_port": 41553,
"stdin_port": 43343,
"control_port": 33591,
"hb_port": 40639,
"ip": "127.0.0.1",
"key": "cfde00e3-b2509ce23915d2d0af176b45",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
} Place the file in the jupyter runtime location of your docker filesystem and then start a kernel using ipython instead on your docker:
This will respect the ports specified in the json file. Then on your local machine:
If the command succeeds you will see an ipython prompt Also, it will create an emacs-ssh.json file which in turn use it in your emacs With the latest emacs-jupyter this is what I need to get it working:
A bit clunky setup but it works ok and does not rely on tramp. I have managed to automate most of these steps with shell scripts. |
what version of ipython do you use? I get:
I guess you mean That does work, but it creates an ssh file with different ports than the ones I specified. This command seems to hang
until I get
I am trying to use the Jupyter Stacks images, which maybe don't support ssh? |
Yes, you are right I could reproduce the issue with that specific docker image. I am not sure why this is not working, the ports are unreachable. Also, ssh is not required since you can bind locally. Sorry for the unhelpful comment. |
Does it work for some other docker image that you use? |
Does it work for some other docker image that you use?
No, I don't use docker containers but I do use kernels that sit in
different network subnets. What I suggested works when I execute
`ipython kernel -f emacs.json` locally and I am unsure why port
forwarding is not working when this docker container is involved.
|
It looks like it might not possible to do this right now without patching jupyter. |
FYI, with what I suggested it looks like you need to expose the rest of the ports here to get it working: https://github.com/jupyter/docker-stacks/blob/main/base-notebook/Dockerfile#L51 |
I have a solution of sorts. It looks like it is necessary to patch jupyter because of this issue: jupyter/jupyter_client#955 (comment). Here are steps that led to a working solution for me. First we modify jupyter so that the ports we specify get used, and not random ones. This is a somewhat fragile way to do this (e.g. the path to the file is Python version dependent(, but as a POC it is ok. It is crucial we start a kernel with these ports because otherwise there is no way to tell which ports to expose when running the image.
Build the docker image.
Start the docker image with published ports and options to the kernel.
We assume there is one of these connection files: #+BEGIN_SRC sh #+RESULTS: Now, copy that file locally.
Now use that kernel file as the :session arg
Note there will be a residual json file when you are done. Maybe a kill-buffer hook could be used to get rid of this. I think it could be possible to wrap this in elisp, but for now I am not doing that. I want to explore an ssh solution first I think. |
I tried following the clues at #61, but I did not succeed.
First, I ran:
This creates a conn file:
I use that in a session:
But this times out:
Requesting kernel info...
or: Timeout before idle: #s(jupyter-org-request "3714e040-b459-4ad6-9f05-caa6cf45bbb7"
It seems like the ports in the kernelspec do not match what is exposed. I guess that is the problem?
I also tried copying this file to my local host like this:
but it also times out. I guess it is related to the ports? I checked these, and they are consistent.
I am using Using elpa/jupyter-20230627.163019.
Any hints on how to make this work?
The text was updated successfully, but these errors were encountered: