[英]Detach from docker run from script without killing container
I have a script which contains this line: 我有一个包含此行的脚本:
fgrep -m 1 'PostgreSQL init process complete' <( docker run --name test-postgres-migration \
-a STDOUT -p 5432:5432 postgres:9.4 )
However, even if I change it to: 但是,即使我将其更改为:
fgrep -m 1 'PostgreSQL init process complete' <( docker run --name test-postgres-migration \
-a STDOUT -p 5432:5432 postgres:9.4 </dev/null )
or: 要么:
fgrep -m 1 'PostgreSQL init process complete' <( docker run --name test-postgres-migration \
-a STDOUT -p 5432:5432 postgres:9.4 </dev/null ) </dev/null
or even when I put the entire line in a separate shell script and wrap it in nohup
: 甚至当我将整行放在单独的shell脚本中并将其包装在
nohup
:
nohup ./boot-container.sh
the docker container still dies if the script is killed (by emacs) when it is on a later line. 如果该脚本在以后的行中被杀死(被emacs杀死),则Docker容器仍然死亡。 This happens because the docker client command is still running, and even though it has PID 1 as its parent, for some mysterious reason (maybe due to a shared
stdin file handle
or tty
) it gets killed too when the script gets killed, which in turn causes the docker container it has started to die. 发生这种情况是因为docker client命令仍在运行,即使它以PID 1作为其父级,由于某种神秘的原因(可能是由于共享的
stdin文件handle
或tty
),它在脚本被杀死时也被杀死了,这在命令行中turn导致它开始死亡的docker容器死亡。 How can I prevent this? 我该如何预防?
In this situation, even nohup
isn't sufficient - it's necessary to use setsid
: 在这种情况下,甚至
nohup
都不足够-必须使用setsid
:
fgrep -m 1 'PostgreSQL init process complete' <( setsid docker run --name test-postgres-migration \
-a STDOUT -p 5432:5432 postgres:9.4 )
This solves my problem on Linux - I haven't verified whether the problem occurs on Mac or Unixes, or if this unofficial port of setsid to Mac and other Unixes fixes it. 这解决了我在Linux上的问题-我尚未验证问题是在Mac还是Unix上发生,还是未将setid 移植到Mac和其他Unixes上进行了修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.