在Docker上使用Systemd的CentOS

我实际上正在使用Gitlab-CI对我的剧本进行自动化testing,Ubuntu工作得很好,没有问题。

我实际上遇到的问题是CentOS和Systemd,首先是Playbook(在CentOS7中安装Postgres 9.5):

- name: Ensure PostgreSQL is running service: name: postgresql-9.5 state: restarted ignore_errors: true when: - ansible_os_family == 'RedHat' 

所以,这是我得到,如果我想在容器内启动postgres:

 Failed to get D-Bus connection: Operation not permitted\nFailed to get D-Bus connection: Operation not permitted\nFailed to get D-Bus connection: Operation not permitted\nFailed to get D-Bus connection: Operation not permitted\nFailed to get D-Bus connection: Operation not permitted\n 

我已经不得不以特权模式运行容器了,还有c组和其他任何东西。 已经尝试了不同Docker容器,但没有任何工作。

在使用docker的时候,我认为最好使用postgres来启动服务器。 像

 postgres -D /opt/postgresql/data/ > /var/log/postgresql/pg_server.log 2>&1 & 

当你使用docker的时候,你没有一个完整的systemd。

您可以使用@KJockerbuild议的解决scheme来创buildpostgresqlfunction容器。 或者你可以configurationsystemd在容器内工作,这里是一个文件检查

在Docker容器上使用Ansible时,我也有同样的事情……而且我写了一个docker-systemctl-replacement 。 它适用于PostgreSQL – 不需要更改Ansible脚本,它可以保留在真实机器上的部署。