注:以下操作針對CentOS 7.2以上操作系統(tǒng),建議CentOS/RHEL7.1以下不要模仿
我們知道,Docker運行一個容器起來的時候,只是為你提供特定的文件系統(tǒng)層和進程隔離,它給你一個VM的感覺卻并不是VM,所以你可能偶爾會想要像在物理機那樣使用systemctl start|status|stop來管理服務(wù)進程,然后你通常會看到
Failed to get D-Bus connection: Operation not permitted
這個錯誤。
原因很簡單:
- 你需要啟動systemd進程
- 你需要特權(quán)
所以你如果想要一個可以使用Systemd的容器,你可以嘗試這樣啟動容器:
cat /etc/redhat-release
//CentOS Linux release 7.2.1511 (Core)
docker run -tdi --privileged centos init
在容器中,你可以使用systemd管理服務(wù)進程了:
yum install -y vsftpd
systemctl start vsftpd
systemctl status vsftpd

引用:
http://developerblog.redhat.com/2014/05/05/running-systemd-within-docker-container/