Docker 没有响应终端中的 CTRL+C [英] Docker not responding to CTRL+C in terminal

查看:91
本文介绍了Docker 没有响应终端中的 CTRL+C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前在使用 Docker 时遇到问题;我正在使用它来运行一个在启动时启动 ipython 笔记本的图像.我想对 ipython notebook 本身进行一些编辑,所以我需要在启动后关闭它.

Having an issue with Docker at the moment; I'm using it to run an image that launches an ipython notebook on startup. I'm looking to make some edits to ipython notebook itself, so I need to close it after launch.

但是,在终端中按 CTRL+C 只会输入^C"作为字符串.似乎没有真正的方法可以使用 CTRL+C 来实际关闭 ipython 笔记本实例.

However, hitting CTRL+C in the terminal just inputs "^C" as a string. There seems to be no real way of using CTRL+C to actually close the ipython notebook instance.

有没有人知道导致这种情况的原因,或者知道任何解决方案?

Would anyone have any clues as to what can cause this, or know of any solutions for it?

推荐答案

这篇文章建议使用 CTRL-Z 作为将进程发送到后台然后通过进程 ID 终止进程的解决方法:无法使用 Ctrl-C 杀死 Python 脚本

This post proposes CTRL-Z as a workaround for sending the process to background and then killing the process by its process id: Cannot kill Python script with Ctrl-C

可能的问题:

  • 程序捕获 ctrl-c 后什么也不做,可能性很小.

  • The program catches ctrl-c and does nothing, very unlikely.

存在未正确管理的后台进程.只有主进程收到信号,子进程挂起.很可能发生了什么.

There are background processes that are not managed correctly. Only the main process receives the signal and sub-processes hang. Very likely what's happening.

建议的解决方案:

  • 检查程序文档,了解它是如何正确启动和停止的.ctrl-c 似乎不是正确的方法.

  • Check the programs documentation on how it's properly started and stopped. ctrl-c seems not to be the proper way.

使用 docker-entrypoint.sh bash 脚本包装程序,该脚本会阻止容器进程并能够捕获 ctrl-c.这个 bash 示例应该会有所帮助:https://rimuhosting.com/知识库/linux/misc/trapping-ctrl-c-in-bash

Wrap the program with a docker-entrypoint.sh bash script that blocks the container process and is able to catch ctrl-c. This bash example should help: https://rimuhosting.com/knowledgebase/linux/misc/trapping-ctrl-c-in-bash

在捕获 ctrl-c 后,为 ipython notebook 调用正确的关闭方法.

After catching ctrl-c invoke the proper shutdown method for ipython notebook.

这篇关于Docker 没有响应终端中的 CTRL+C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆