看了許多解決方案,但是對於新手來說並不友好,不是特別清楚
報錯內容:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
解決方法:
docker run -itd --privileged --name myCentos centos /usr/sbin/init
創建完成后: 請使用以下命令進入容器
docker exec -it myCentos /bin/bash
加粗的內容要特別注意,不能遺忘
原因就是: 默認情況下,在第一步執行的是 /bin/bash,而因為docker中的bug,無法使用systemctl
所以我們使用了 /usr/sbin/init 同時 --privileged 這樣就能夠使用systemctl了,但覆蓋了默認的 /bin/bash
因此我們如果想進入容器 就不能再使用 docker attach myCentos
而只能使用 docker exec -it myCentos /bin/bash 因為 exec 可以讓我們執行被覆蓋掉的默認命令 /bin/bash
同時 -it 也是必須的。
對於ubuntu 也類似,可能init 目錄不太相同
當然具體什么bug 我是不知道的,期望以后會會修復