首页 > 解决方案 > 在 Redis (Debian GNU) 容器的任何目录中都找不到 shutdown 和 systemctl

问题描述

我正在尝试在 redis 容器上发出关闭命令。我使用的图像是redis.

我尝试了以下所有方法:

shutdown -h now
/sbin/shutdown -h now
/bin/shutdown -h now
systemctl poweroff

他们都说找不到命令。

操作系统信息:(来自cat /etc/*-release

PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

标签: linuxbashdockerredisdebian

解决方案


您使用的图像不包含这些二进制文件,尤其是 systemctl。

容器应该尽可能快地初始化,并且拥有一个功能齐全的初始化系统会再次达到这个目的,因为它们会产生开销。

这就是为什么使用较小的 init 系统来处理容器的原因,例如tini

请记住,容器是在主机内核中运行的进程,因此您应该从主机停止和启动它们。Docker 具有执行此操作所需的所有实用程序。


推荐阅读