docker - 用于 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中犯了一些错误吗?
解决方案
这是因为您USER node
在 Dockerfile 的末尾使用来启动 sshd,我猜您想使用它node user
来启动npm
.
但是,建议的方法是使用root
to start sshd & use node
to start ,你可以在这里看到一个使用相同解决方案npm
的著名项目redis
然后,您需要进行下一个修复:
USER node
在 Dockerfile 末尾删除之前的CMD
.RUN chmod 0444 /etc/ssh/*
在您的 dockerfile 中删除否则,它会报告下一个使 sshd 不起作用:
'/etc/ssh/ssh_host_ecdsa_key' 的权限 0444 太开放。
删除
RUN echo 'PermitRootLogin=without-password' >> /etc/ssh/sshd_config
,使用 next 替换:RUN echo 'PermitRootLogin=yes' >> /etc/ssh/sshd_config
添加
RUN apt-get install -y gosu
Dockerfile 以安装 gosu,稍后将在entrypoint.sh
在
entrypoint.sh
中,更改exec "$@"
为下一个:exec gosu node "$@"
这将确保
npm start
仍然使用用户节点运行。
然后,你可以看到当启动容器时,sshd 工作,你可以根据service ssh stop && service ssh start
需要重新启动服务,但是由于容器现在运行 sshd 很好,我想你不需要再使用这个了。
推荐阅读
- git - 从 Git 迁移到具有完整历史记录的 SVN
- python - 即使用户和密码正确,Postgresql/psycopg2 密码验证错误
- tensorflow - Inception v3 的迁移学习返回相同的预测
- java - 如何以编程方式触发 Spark Java Web 框架请求
- mysql - MYSQL - 返回查询 A 或查询 B,但不能同时返回。如果两者都存在,则查询 A 的返回结果
- c# - 无法从单独文件夹的控制器访问视图
- regex - 正则表达式关键字搜索接近日期
- r - 计算总和并处理 NA
- stm32 - STM32F429 发现 - 无法使用 SPI 和 DMA 来驱动 WS2812B LED
- webassembly - WASM 运行时何时会集成到 Envoy 代理中