docker run -itd --privileged --name=apache -v /var/www/html/:/var/www/html/ -p 8888:80 myapache:v1 /usr/sbin/init
切记切记
报错内容:
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 也是必须的。
本文讲述了如何在Docker中使用--privileged选项解决`System not booted with systemd in PID1`错误,通过`docker exec-it`进入容器并避免`bin/bash`被覆盖的问题。关键在于理解systemctl的使用和容器默认shell的覆盖。
5735

被折叠的 条评论
为什么被折叠?



