在尝试将visual studio代码附加到WordPress荚(使用kubernetes扩展)时获取以下信息:
An error occurred attaching to the container
在终端中显示以下内容:
[3 ms] Remote-Containers 0.166.0 in VS Code 1.55.0 (c185983a683d14c396952dd432459097bc7f757f).
[48 ms] Start: Resolving Remote
[51 ms] Start: Run: kubectl exec -it wp-test-2-wordpress-65859bfc97-qtr9w --namespace default --container wordpress -- /bin/sh -c VSCODE_REMOTE_CONTAINERS_SESSION='5875030e-bcef-47a6-ada5-7f69edb5d9091617678415893' /bin/sh
[56 ms] Start: Run in container: id -un
[279 ms] 1001
[279 ms] Unable to use a TTY - input is not a terminal or the right kind of file
id: cannot find name for user ID 1001
[279 ms] Exit code 1
[281 ms] Command in container failed: id -un我没有这样的问题,做完全相同的操作,对任何其他舵释放。只与Bitnami WordPress头盔发行版。
发布于 2021-04-06 11:01:49
这是因为Bitnami WordPress映像(version 9.0.0)被迁移到“非根”用户方法中。从现在开始,容器和Apache守护进程都以用户1001的身份运行。
您可以在Bitnami WordPress文档中找到更多信息。
Bitnami WordPress映像被迁移到“非根”用户方法。以前,容器作为根用户运行,Apache守护进程作为守护进程用户启动。从现在开始,容器和Apache守护进程都以用户1001的身份运行。您可以通过将参数securityContext.runAsUser和securityContext.fsGroup设置为0来恢复此行为。图表标签和进题配置也进行了调整,以遵循Helm图表的最佳实践。
发生此问题是因为在id -un Pod中运行WordPress命令会导致错误:
$ kubectl exec -it my-1-wordpress-756c595c9c-497xr -- bash
I have no name!@my-1-wordpress-756c595c9c-497xr:/$ id -un
id: cannot find name for user ID 1001作为解决办法,您可以将WordPress作为一个root运行,方法是设置参数securityContext.runAsUser,并将securityContext.fsGroup设置为0,如Bitnami WordPress文档中所述。
为了演示起见,我只更改了containerSecurityContext.runAsUser参数:
$ helm install --set containerSecurityContext.runAsUser=0 my-1 bitnami/wordpress然后我们可以检查id -un命令的输出:
$ kubectl exec -it my-1-wordpress-7c44f695ff-f9j9f -- bash
root@my-1-wordpress-7c44f695ff-f9j9f:/# id -un
root如您所见,id -un命令不会造成任何问题,因此我们现在可以成功地连接到特定的容器。
我知道这种解决方法并不理想,因为使用非根容器有许多优点。不幸的是,在这种情况下,如果不修改Dockerfile,我就不知道任何其他解决方案。
https://stackoverflow.com/questions/66962261
复制相似问题