gotty使用問題,Docker container won't exit by closing browser window 問題處理

bug描述參見 https://github.com/yudai/gotty/issues/88git

解決方案(繞過):github

1.假設容器中運行的進程是bash或sh瀏覽器

2.關閉瀏覽器時,gotty不要發送closeSignal信號給bash進程,改爲發送exit命令,這樣容器中bash或sh進程能夠退出bash

 

修改local_command.go文件code

修改前進程

func (lcmd *LocalCommand) Close() error {
	if lcmd.cmd != nil && lcmd.cmd.Process != nil {
		lcmd.cmd.Process.Signal(lcmd.closeSignal)
	}

 

修改後cmd

func (lcmd *LocalCommand) Close() error {
	log.Println("LocalCommand.Close, cmd=", lcmd.cmd)

	if lcmd.cmd != nil && lcmd.cmd.Process != nil {
		// stop /bin/bash process
		_, err := lcmd.Write([]byte("\n\rexit\n\r"))
		log.Println("send exit, err=", err)
		err = lcmd.pty.Close()
		log.Println("pty close, err=", err)

	}
相關文章
相關標籤/搜索