当我在 Laravel v9.0 中运行这段代码时,
$process = new Process(['sudo','docker','login','-u',$this->git_username,'-p',$this->git_token,$this->docker_image_url]); $process->setTty(true); $process->run();`
我不断收到此错误
"TTY mode requires /dev/tty to be read/writable."
在参考 laravel 文档时,我注意到这个过程在版本 10 中可用。但是如果我删除
$process->setTty(true);
,它运行良好。但我需要使用 sudo 运行,因为需要 root 权限。
请帮助我,提前致谢。
当我在没有
sudo
和 $process->setTty(true);
的情况下运行时
这就是结果
WARNING! Using --password via the CLI is insecure. Use --password-stdin. permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/auth": dial unix /var/run/docker.sock: connect: permission denied
当我在进程中只运行
$process->setTty(true);
时
这就是结果
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required
我也有同样的问题。 我认为 tty 模式不可能以编程方式实现。我改用 shell_exec 函数,它对我来说效果很好。
举个例子,
$process = shell_exec ('sudo docker login -u '.$this->git_username.' -p '.$this->git_token.' '.$this->docker_image_url]);