我正在为任何Linux发行版上install nginx的Ansible.Galaxy编写ansible playbook。 但我觉得用Travis CI和Docker在包含Systemd的图像上进行测试。因为SystemD给出了错误:
无法获得D-Bus连接:没有与服务管理器的连接。
正如您所见https://travis-ci.org/weldpua2008/ansible-nginx/jobs/78864352 有错误。
所以我试着代表它:
~# git clone https://github.com/weldpua2008/ansible-nginx.git
~# cd ansible-nginx
~# docker run -ti --rm=true -v `pwd`:/ansible-nginx:rw centos:7 /bin/bash ^C
~# cd ansible-nginx/
~/ansible-nginx# docker run -ti --rm=true -v `pwd`:/ansible-nginx:rw centos:7 /bin/bash
[root@2f6955a46b42 /]# /ansible-nginx/tests/test-on-rpm.sh
TASK: [ansible-nginx | create document root directory if needed] **************
ok: [localhost]
TASK: [ansible-nginx | Starting nginx service] ********************************
failed: [localhost] => {"failed": true}
msg: no service or tool found for: nginx
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/root/test.retry
localhost : ok=5 changed=2 unreachable=0 failed=1
也许没有这项服务?
[root@2f6955a46b42 /]# systemctl enable nginx.service
[root@2f6955a46b42 /]# systemctl -t service -a
Failed to get D-Bus connection: No connection to service manager.
[root@2f6955a46b42 /]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
我是如何尝试在ansible中启动服务的:https://github.com/weldpua2008/ansible-nginx/blob/master/tasks/main-centos.yml#L24
- name: Starting nginx service
service: name=nginx state=started
tags:
- nginx
联系解决
答案 0 :(得分:0)
这是因为Docker(普通"无特权")容器没有运行systemd
的权限(因为它想要访问/sys/fs/cgroup
文件系统)。
但这真的是因为Docker容器更喜欢运行一个进程,你尝试使用它们的进程 - 将它们视为"一个带有大量支持实用程序的Unix进程"而不是"微型的VM"
你需要一个简单的Dockerfile继承自Centos,它安装nginx
然后有一个最终的CMD
,如下所示:
CMD /usr/sbin/nginx -g "daemon off;"
有关提示,请参阅官方nginx
Dockerfile this page