0

我有 ansible playbook 工作,但是在尝试用分子测试它时,我无法启动 docker 服务。

这是我在分子.yml 中的内容

platforms:
- name: instance
  image: oraclelinux:7
  command: /usr/sbin/init
  tmpfs:
   - /run
   - /run/lock
   - /tmp
 capabilities:
   - SYS_ADMIN
 volumes:
   - /sys/fs/cgroup:/sys/fs/cgroup:ro
 port_bindings:
   2424: 2424,
   2480: 2480
 pre_build_image: true

当我运行我的 ansible playbook 时,我使用以下命令来创建 docker 容器:

docker run -it --name=testing -d --rm --privileged --cap-add=SYS_ADMIN --tmpfs /run --tmpfs /run/lock --tmpfs /tmp -p 2424:2424 -p 2480:2480 -v /sys/fs/cgroup:/sys/fs/cgroup:ro  oraclelinux:7  /usr/sbin/init

用分子测试时出错:

    TASK [docker-role : Start docker] ******************************************
    fatal: [instance]: FAILED! => {"changed": true, "cmd": "sudo systemctl start docker", 
"delta": "0:00:00.613116", "end": "2020-10-21 03:24:47.268335", "msg": "non-zero return code", 
"rc": 1, "start": "2020-10-21 03:24:46.655219", "stderr": "Job for docker.service failed because 
the control process exited with error code. See \"systemctl status docker.service\" and 
\"journalctl -xe\" for details.", "stderr_lines": ["Job for docker.service failed because the 
control process exited with error code. See \"systemctl status docker.service\" and \"journalctl 
-xe\" for details."], "stdout": "", "stdout_lines": []}

我如何弄清楚分子测试的问题是什么?

更新:

    [root@instance /]# systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Wed 2020-10-21 07:05:55 UTC; 2min 22s ago
     Docs: https://docs.docker.com
  Process: 17373 ExecStart=/usr/bin/dockerd -g /tmp (code=exited, status=1/FAILURE)
 Main PID: 17373 (code=exited, status=1/FAILURE)

Oct 21 07:05:55 instance systemd[1]: start request repeated too quickly for docker.service
Oct 21 07:05:55 instance systemd[1]: Failed to start Docker Application Container Engine.
Oct 21 07:05:55 instance systemd[1]: Unit docker.service entered failed state.
Oct 21 07:05:55 instance systemd[1]: docker.service failed.
Oct 21 07:06:13 instance systemd[1]: start request repeated too quickly for docker.service
Oct 21 07:06:13 instance systemd[1]: Failed to start Docker Application Container Engine.
Oct 21 07:06:13 instance systemd[1]: docker.service failed.
Oct 21 07:06:34 instance systemd[1]: start request repeated too quickly for docker.service
Oct 21 07:06:34 instance systemd[1]: Failed to start Docker Application Container Engine.
Oct 21 07:06:34 instance systemd[1]: docker.service failed.


[root@instance /]# docker info
Client:
 Debug Mode: false

Server:
ERROR: Cannot connect to the Docker daemon at 
unix:///var/run/docker.sock. Is the docker daemon running?

    # journalctl -xe
-- 
-- Unit docker.socket has finished shutting down.
Oct 21 07:09:13 instance systemd[1]: Stopping Docker Socket for the API.
-- Subject: Unit docker.socket has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit docker.socket has begun shutting down.
Oct 21 07:09:13 instance systemd[1]: Starting Docker Socket for the API.
-- Subject: Unit docker.socket has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit docker.socket has begun starting up.
Oct 21 07:09:13 instance systemd[1]: Listening on Docker Socket for the API.
-- Subject: Unit docker.socket has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit docker.socket has finished starting up.
-- 
-- The start-up result is done.
Oct 21 07:09:13 instance systemd[1]: start request repeated too quickly for docker.service
Oct 21 07:09:13 instance systemd[1]: Failed to start Docker Application Container Engine.
-- Subject: Unit docker.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit docker.service has failed.

我的理解是它需要在安装了 docker 的 docker 容器中运行并且需要启动它的服务。

4

1 回答 1

0

也许我不太了解这个问题,但是对于分子,您不需要运行容器,分子会为您完成。

你可以试试这个:

molecule create # This would create the instance
molecule list # This would show you the molecule scenario status
molecule converge # This would run you molecule playbook that would run the role

实际上molecule test命令将运行所有这些步骤:

    --> Test matrix

└── default
    ├── lint
    ├── destroy
    ├── dependency
    ├── syntax
    ├── create
    ├── prepare
    ├── converge
    ├── idempotence
    ├── side_effect
    ├── verify
    └── destroy

要使应用了角色的容器可用,您需要运行converge命令。

一旦收敛,您也可以通过分子进入容器:

molecule login --host instance
于 2021-02-01T21:36:13.997 回答