以 firewalld 爲例.
1. 問題
安裝完 firewall, 發現 systemctl start firewalld 報錯.
yum install firewalld
報錯:
System has not been booted with systemd as init system (PID 1). Can’t operate. Failed to connect to bus: Host is down
2. 解決
運行容器時, 添加兩個參數:
--privileged=true
/usr/sbin/init
docker run -d -it --privileged=true --name centos centos /usr/sbin/init
由於運行是添加了
/usr/sbin/init
參數, 進入容器時用/bin/bash
即可.
docker exec -it centos /bin/bash
此時再運行
systemctl start firewalld
便可以成功.