bash_kernel icon indicating copy to clipboard operation
bash_kernel copied to clipboard

Can't use docker run / docker attach

Open axsaucedo opened this issue 8 years ago • 2 comments

If I run a docker container or attach, the ipython notebook just hangs until the container is stopped.

docker run -i -t centos:centos6 /bin/bash

or

docker run -d -i -t centos:centos6 /bin/bash
docker attach [CONTAINER_ID]

I'm not sure if it would be possible to attach to the docker container and treat that as a single command, so I can show commands that are ran inside the container as the notebook progresses.

axsaucedo avatar Mar 12 '17 11:03 axsaucedo

For now, the walkarounds are to just run docker with -d, so it runs in the backgound, and then run all commands with:

docker exec [CONTAINER_ID] bash -c "[COMMANDS]"

You can find an example of this on my Docker Notebook

axsaucedo avatar Mar 12 '17 13:03 axsaucedo

This is unfortunately a general limitation of the Jupyter model - you can only run subprocesses that print some output and then exit, not ones that expect to interact with the user. There isn't a good way to tell when a subprocess is waiting for input.

In this particular case, you may be able to trick it into thinking that the command has finished. It's running bash in a pseudoterminal, looking for the prompt [PEXPECT_PROMPT> and continuation prompt [PEXPECT_PROMPT+. If you can arrange for those to be PS1 and PS2 in bash inside your docker container, it should let you run notebook cells inside your docker container. This is rather a hack, though, and there may be some weird hiccups.

takluyver avatar Mar 15 '17 11:03 takluyver