首页 > 解决方案 > 用于 ssh 自动启动的 dockerfile ssh 僵尸进程

问题描述

嗨,我在使用容器自动启动 sshd 时遇到了一些大问题。

我的码头文件: 码头文件

我的入口点: 入口点

当我进入容器 bash 时,输入:

服务 ssh 状态

[FAIL] sshd is not running ... failed!

我也得到了僵尸 ssh 进程:-|

ps -ef | grep ssh

node        15     1  0 14:49 ?        00:00:00 [sshd] defunct

node       183   142  0 14:59 pts/0    00:00:00 grep ssh

我在dockerfile中犯了一些错误吗?

标签: dockersshdockerfilezombie-process

解决方案


这是因为您USER node在 Dockerfile 的末尾使用来启动 sshd,我猜您想使用它node user来启动npm.

但是,建议的方法是使用rootto start sshd & use nodeto start ,你可以在这里看到一个使用相同解决方案npm的著名项目redis

然后,您需要进行下一个修复:

  1. USER node在 Dockerfile 末尾删除之前的CMD.
  2. RUN chmod 0444 /etc/ssh/*在您的 dockerfile 中删除

    否则,它会报告下一个使 sshd 不起作用:

    '/etc/ssh/ssh_host_ecdsa_key' 的权限 0444 太开放。

  3. 删除RUN echo 'PermitRootLogin=without-password' >> /etc/ssh/sshd_config,使用 next 替换:

    RUN echo 'PermitRootLogin=yes' >> /etc/ssh/sshd_config
    
  4. 添加RUN apt-get install -y gosuDockerfile 以安装 gosu,稍后将在entrypoint.sh

  5. entrypoint.sh中,更改exec "$@"为下一个:

    exec gosu node "$@"
    

    这将确保npm start仍然使用用户节点运行。

然后,你可以看到当启动容器时,sshd 工作,你可以根据service ssh stop && service ssh start需要重新启动服务,但是由于容器现在运行 sshd 很好,我想你不需要再使用这个了。


推荐阅读