Rog*_*oto 5 unix ssh shell jenkins docker
我目前在docker容器中使用Jenkins实例。该图像恰好使用Tini作为PID1。当我尝试使用以下命令向其中打开外壳时:
$ docker exec -it jenkins /bin/bash
Run Code Online (Sandbox Code Playgroud)
我得到这个作为用户名:
I have no name!@<container_id_hash>:/$
Run Code Online (Sandbox Code Playgroud)
这使我无法使用在此容器中运行的Jenkins作业的shell出生的ssh命令:
$ ssh
$ No user exists for uid 497
$ id
$ uid=497 gid=495 groups=495
Run Code Online (Sandbox Code Playgroud)
我尝试在/ etc / passwd中为该uid创建一个用户,并在/ etc / group中为该gid创建一个组,但这没关系!
我只能以jenkins用户身份登录才能手动运行ssh:
$ docker exec -it --user=jenkins jenkins /bin/bash
Run Code Online (Sandbox Code Playgroud)
我可以使用ssh相关插件解决这个问题。但是我真的很好奇,为什么只有在使用Tini作为ENTRYPOINT的docker镜像中才会发生这种情况。
更新1
我在/ etc / passwd中做了这样的事情:
jenkins:x:497:495::/var/jenkins_home:/bin/bash
这在/ etc / group中:
jenkins:x:495:
还尝试了其他名称,例如yesihaveaname和yesihaveagroup,jenkins
更新2
我一直在与Tini的开发人员联系,他不认为导致此问题的原因是Tini,因为它不会缠住uid或gid,任何其他潜在客户都会被感激。
更新
很高兴知道(这很容易,所以我忽略了一段时间 *facepalm*):
要以 root 身份登录到容器,只需提供--user root您的 exec 命令 - 例如:
docker exec -ti -u root mycontainername bash...无需复制 passwd 文件并设置pw-哈希...
就像您发布的链接所说的那样,容器内的 UserID 可能没有分配名称。
(虽然我不使用 Tini... )我解决了这个问题如下:
1.) 在容器内执行 ( docker exec -ti mycontainername sh):
id # shows the userid (e.g. 1234) and groupid (e.g. 1235) of the current session
Run Code Online (Sandbox Code Playgroud)
2.) 在容器外(在本地机器上)执行:
docker cp mycontainername:/etc/passwd /tmp # this copies the passwd-file to from inside the container to my local /tmp-directory
echo "somename:x:1234:1235:somename:/tmp:/bin/bash" >> /tmp/passwd # add some username *!!with the userid and groupid from the output!!* of the `id` command inside the container (CAUTION: do NOT overwrite, do JUST APPEND to the file) - "1234" is just exemplary, do not use it
docker cp /tmp/passwd mycontainername:/etc/passwd # copy the file back, overwriting the /etc/passwd inside the container
Run Code Online (Sandbox Code Playgroud)
现在docker exec -ti mycontainername sh再次登录到容器 ( )。
PS如果你知道容器的root密码你现在可以切换到root如果你没有它,你可以将“/etc/shadow”文件复制出容器(如上),然后编辑root-entry使用已知的密码哈希**,然后将其复制回容器,然后登录到容器并运行su)
**要在您的本地系统上获取此密码哈希:(1) 添加一个临时 testuser ( sudo useradd testdumpuser) (2) 将此用户作为密码 ( sudo passwd testdumpuser) (3) 在/etc/shadow-file 中查找“testdumpuser”条目并复制此长第一个“:”之后的奇数字符串,直到第二个“:”
| 归档时间: |
|
| 查看次数: |
1984 次 |
| 最近记录: |