1. 程式人生 > 其它 >-----System has not been booted with systemd as init system (PID 1). Can‘t operat

-----System has not been booted with systemd as init system (PID 1). Can‘t operat

報錯現象如下

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

解決方案一

檢查啟動命令 加引數 -itd --privileged 如果dockerfile中CMD中沒有執行 要在後面命令加/usr/sbin/init

dockerun --privileged -itd --name systemctl3 -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemctl:test

解決方案二

重啟一個docker在後臺執行 執行上面的命令 dockerun --privileged -itd --name systemctl3 -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemctl:test

原因詳解

–privateged 使container內的root擁有真正的root許可權,不進行降權處理。否則,容器內的使用者只是外部的一個普通使用者,普通使用者還想訪問核心?讓systemctl管理系統? 而且預設情況下,在第一步執行的是 /bin/bash 所以我們使用了 /usr/sbin/init覆蓋/bin/bash

同時 只能使用 docker exec -it systemctl5 /bin/bash 因為 exec 可以讓我們執行被覆蓋掉的預設命令 /bin/bash 同時 -it 也是必須的。