原本已经用 docker 部署好了 PHP的 container,以及 composer 的依赖。
最近需要更新一个依赖,执行 “`dcoker-compose exec php composer require “myTeam/xxxx”“`却报:
[runtimeexception]
Failed to execute git clone --mirror "git@gitlab.com:XXXXXX" "~/.cache/composer/vcs/bitbucket.orgXXXXXXXX.git/"
Cloning into bare repository '"~/.cache/composer/vcs/bitbucket.orgXXXXXXXX.git'…
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
查了网上其它人方案,都无法解决,例如:
1.修改 ~/.ssh/ 下 config 及 id_rsa, id_rsa.pub, known_hosts 等文件的权限为 600 或 400
https://stackoverflow.com/questions/51744040/docker-bad-owner-or-permissions-on-root-ssh-config
https://serverfault.com/questions/253313/ssh-returns-bad-owner-or-permissions-on-ssh-config
https://github.com/welaika/docker-wordmove/issues/16
2.清除 composer 缓存
https://www.cnblogs.com/songyanan/p/13294282.html
3.确认 Git 环境变量 或 用户名密码/token
https://stackoverflow.com/questions/17792588/composer-says-git-not-found/17794382#17794382
https://blog.csdn.net/qq_16885135/article/details/52072257
https://blog.csdn.net/will5451/article/details/51995629
4.把 docker 的 container、image 全部删掉,重新部署
……
……
以上种种都不能解决
后面判断主要问题还是在 ~/.ssh/中各个文件的权限上,因为 docker container 里的ssh文件是从Ubuntu中复制进去的,权限属性跟Ubuntu下的 ~/.ssh/ 一样,唯一不同的是 container 里面的 owner 是 1000
docker-compose exec php bash 进入container
而 container 中使用的是 root , 所以试着把这4个文件的 owner 改为 root
退出,再执行“`dcoker-compose exec php composer require “myTeam/xxxx”“`,终于可以正常更新了。
2021/03/02
【后续】
今天是 2021/04/13,执行 docker-compose exec php composer install
时又报 RuntimeException 了~ 提示如下
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 3 installs, 0 updates, 0 removals
- Syncing aaa/xxxx (v0.1.2) into cache
[RuntimeException]
Failed to execute git clone --mirror 'git@bitbucket.org:dbstech/xxxx.git' '/root/.cache/composer/vcs/git-bitbucket.org-dbstech-xxxx.git/'
Cloning into bare repository '/root/.cache/composer/vcs/git-bitbucket.org-dbstech-xxxx.git'...
Bad owner or permissions on /root/.ssh/config
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-scripts] [--no-progress] [--no-install] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>]...
ERROR: 1
折腾了半天,用尽之前的办法还是无法解决,后面又找到了一个新的处理方法
sudo chown root:$USER ~/.ssh/config
sudo chmod 644 ~/.ssh/config
docker-compose exec php composer clear
docker-compose exec php composer install
注意:
1.如果 composer clear 后还是无法安装,可以试着手动把 ~/.cache/composer/ 下的 vcs 目录删除一下
2.我登录的用户并不是root,只是把当前用户加入【docker组】和【root组】
参考:
https://stackoverflow.com/questions/51744040/docker-bad-owner-or-permissions-on-root-ssh-config