容器内使用systemctl 命令时出现(System has not been booted with systemd as init system (PID 1). Can't operat....信息。
时间: 2023-11-16 20:02:07 浏览: 37
当在容器内使用systemctl命令时,可能会出现“System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down”这样的错误信息。这是因为容器内没有systemd进程作为init进程,而systemctl命令需要systemd进程作为init进程才能正常运行。解决这个问题的方法是在启动容器时加上--privileged参数,并在容器内运行systemd进程作为init进程。具体步骤如下:
1. 运行centos容器:docker run -itd --name centos centos /bin/bash
2. 停止并删除容器:docker stop centos && docker rm centos
3. 运行centos容器并获取systemd权限:docker run --privileged -itd --name centos centos /usr/sbin/init
4. 进入容器终端:docker exec -it centos /bin/bash
相关问题
使用systemctl命令报错System has not been booted with systemd as init system (PID 1). Can't operate.
使用systemctl命令报错"System has not been booted with systemd as init system (PID 1). Can't operate"是由于容器中的init系统不是systemd导致的。Docker容器默认使用的是docker-init作为init系统,而不是systemd。因此,无法使用systemctl命令来管理服务。
在Docker容器中,如果需要使用systemctl命令来管理服务,可以使用以下方法之一:
1. 使用systemd镜像:可以使用systemd镜像来构建Docker容器,使容器中的init系统为systemd。这样就可以正常使用systemctl命令来管理服务。
2. 使用systemd-nspawn:systemd-nspawn是systemd提供的一个工具,可以在容器内模拟系统引导。使用systemd-nspawn可以创建一个与宿主机几乎相同的环境,包括init系统。这样,在容器中就可以使用systemctl命令来管理服务。
docker systemctl System has not been booted with systemd as init system (PID 1). Can't operate
引用:当使用命令systemctl时,报错信息为"System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down"。
这个错误意味着docker容器内的操作系统没有使用systemd作为初始化系统(PID 1)。在这种情况下,systemctl命令无法正常工作。
解决这个问题的方式是在docker容器内使用一个PID为1的init系统,例如使用supervisord或runit作为init系统。这样就可以正常使用systemctl命令了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [docker报错:System has not been booted with systemd as init system (PID 1). Can‘t operate.](https://blog.csdn.net/mouday/article/details/128449952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [Docker: System has not been booted with systemd as init system (PID 1). Can‘t operate.](https://blog.csdn.net/m0_46304383/article/details/121483556)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]