在docker'systemctl错误'连接到总线失败:没有这样的文件或目录'

我用dockerUbuntu上使用Ubuntu-16.04镜像在本地testing我的食谱。 在做kitchen converge ,我收到以下错误。 我发现systemctl工作不正常。 有人可以帮助我解决这个问题任何其他方式来实现相同的事情?

  [2017-11-30T15:22:30+00:00] INFO: Running queued delayed notifications before re-raising exception Running handlers: [2017-11-30T15:22:30+00:00] ERROR: Running exception handlers Running handlers complete [2017-11-30T15:22:30+00:00] ERROR: Exception handlers complete Chef Client failed. 9 resources updated in 06 seconds [2017-11-30T15:22:30+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out [2017-11-30T15:22:30+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report [2017-11-30T15:22:30+00:00] ERROR: envoy_auth_apps_setup[default-service] (envoy_auth_apps::_default line 1) had an error: Chef::Exceptions::MultipleFailures: Multiple failures occurred: * Mixlib::ShellOut::ShellCommandFailed occurred in chef run: execute[systemctl daemon-reload] (/tmp/kitchen/cache/cookbooks/envoy_auth_apps/resources/setup.rb line 133) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1' ---- Begin output of systemctl daemon-reload ---- STDOUT: STDERR: Failed to connect to bus: No such file or directory ---- End output of systemctl daemon-reload ---- Ran systemctl daemon-reload returned 1 * Mixlib::ShellOut::ShellCommandFailed occurred in delayed notification: service[envoy] (/tmp/kitchen/cache/cookbooks/envoy_auth_apps/resources/setup.rb line 194) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1' ---- Begin output of /bin/systemctl --system restart envoy ---- STDOUT: STDERR: Failed to connect to bus: No such file or directory ---- End output of /bin/systemctl --system restart envoy ---- Ran /bin/systemctl --system restart envoy returned 1 [2017-11-30T15:22:30+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) >>>>>> ------Exception------- >>>>>> Class: Kitchen::ActionFailed >>>>>> Message: 1 actions failed. >>>>>> Converge failed on instance <default-ubuntu>. Please see .kitchen/logs/default-ubuntu.log for more details >>>>>> ---------------------- >>>>>> Please see .kitchen/logs/kitchen.log for more details >>>>>> Also try running `kitchen diagnose --all` for configuration 

这是我的.kitchen.yml

 --- driver: name: docker binary: /usr/local/bin/docker use_sudo: false network: - ["public_network", "bridge: 'en0: Wi-Fi (AirPort)'"] provisioner: name: chef_zero require_chef_omnibus: "12.21.14" environments_path: test/integration/environments nodes_path: test/integration/nodes data_bags_path: test/integration/data_bags client_rb: environment: development verifier: name: inspec platforms: - name: ubuntu driver_config: image: ubuntu:xenial platform: ubuntu # provision_command: # - apt-get -y install dbus suites: - name: default run_list: # - recipe[base_app] - recipe[envoy_auth_apps::_default] verifier: inspec_tests: - test/integration/default attributes: nameserver: domain_name: 'kitchen.xyz.io' envoy_auth_apps: consul_client_enabled: false 

kitchen-docker是不是真的设置与systemd工作。 我会推荐使用kitchen-dokken ,这样做很容易。

通常Docker不支持容器中的systemd服务,但是你可以使用一个特殊的Ubuntu系统映像和一些额外的主机configuration。 请注意,这个图像不build议在生产中运行。

首先,你需要设置你的主机能够运行这个图像:

docker run --rm --privileged -v /:/host solita/ubuntu-systemd setup

然后,你将能够使用systemd运行容器(添加必要的坐标和标志):

 docker run -d --name systemd --security-opt seccomp=unconfined \ --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ -t solita/ubuntu-systemd 

是的,还有另外一种方法可以达到同样的效果! 您可以尝试用https://github.com/gdraheim/docker-systemctl-replacementreplace标准systemd systemctl,而它在令人惊讶的环境中工作,它迄今尚未与厨房testing。 请提供一些反馈,如果你试试看。