错误信息:
panic: inappropriate ioctl for device
goroutine 33 [running]:
mysql_backup/service.(*Cli).RunTerminal(0xc0000b4b10?, {0xc00019e1c0, 0x6c}, {0x80b000?, 0xc0000ac008}, {0x80b000?, 0xc0000ac000})
/Users/zhenyang/codes/database_backup/mysql_backup/service/ssh.go:103 +0x49d
mysql_backup/jobs.(*DownloadSqlFileJob).dumpContainerSql(...)
/Users/zhenyang/codes/database_backup/mysql_backup/jobs/download_sqlfile.go:80
mysql_backup/jobs.(*DownloadSqlFileJob).run(0xc0001ac240)
/Users/zhenyang/codes/database_backup/mysql_backup/jobs/download_sqlfile.go:55 +0x19b
mysql_backup/jobs.(*DownloadSqlFileJob).Run(0x0?)
/Users/zhenyang/codes/database_backup/mysql_backup/jobs/download_sqlfile.go:26 +0x67
github.com/robfig/cron/v3.(*Cron).startJob.func1()
/Users/zhenyang/go/pkg/mod/github.com/robfig/cron/[email protected]/cron.go:312 +0x6a
created by github.com/robfig/cron/v3.(*Cron).startJob
/Users/zhenyang/go/pkg/mod/github.com/robfig/cron/[email protected]/cron.go:310 +0xad
错误代码抛出位置:
fd := int(os.Stdin.Fd())
oldState, err := term.MakeRaw(fd)
if err != nil {
panic(err)
}
defer term.Restore(fd, oldState)
错误复现
我项目中需要通过ssh操作远程服务器,使用的包是
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
"golang.org/x/term"
宿主机测试运行的时候这里是没有问题的。在容器中就会报错。
解决方案
找了半天,网上的其他的同类报错都没有找到靠谱的解决方案,最后问的chatgpt解决的,回复如下
问题错误现在我的容器启动的指令,没有分配终端,启动添加-it 参数,解决问题。留下没有技术的眼泪。手动滑稽!