简体   繁体   English

docker 守护进程开始使用 ansible

[英]docker daemon start using ansible

I am working on ansible script for start docker damon, docker container, docker exec After start docker container with in the docker container i need to start some services. I am working on ansible script for start docker damon, docker container, docker exec After start docker container with in the docker container i need to start some services.

I have installed docker engine, configured and working with some docker container in remote machines.我已经安装了 docker 引擎,在远程机器中配置并使用了一些 docker 容器。 i have used to start docker daemon with specific path, because i need to store my volumes and containers with in path.我曾经使用特定路径启动 docker 守护程序,因为我需要使用路径存储我的卷和容器。

 $docker daemon -g /test/docker

My issue is when start the docker daemon its started, but not go to next process.我的问题是当启动 docker 守护程序时它启动了,但不是 go 到下一个进程。 via ansible.通过 ansible。 still running docker daemon.仍在运行 docker 守护进程。

  ---
  - hosts: webservers
    remote_user: root

   # Apache Subversion   dnf -y install python-pip

    tasks:

      - name: Start Docker Deamon
        shell: docker -d -g /test/docker 
        become: yes
        become_user: root

      - name: Start testing docker machine
        command: docker start testing
        async: True
        poll: 0

I follow async to start the process ,but its not working for me,我遵循 async 来启动该过程,但它对我不起作用,

Suggest me After start docker daemon, How to run next process.建议我启动 docker 守护程序后,如何运行下一个进程。

In order to start the docker daemon you should use the ansible service module : 要启动docker守护程序,您应该使用ansible 服务模块

- name: Ensure docker deamon is running
  service:
    name: docker
    state: started
  become: true

any docker daemon customisation should be placed in /etc/docker/daemon.json as described in official documentation . 任何docker守护程序自定义应该放在/etc/docker/daemon.json中 ,如官方文档中所述 in your case the file would look like: 在您的情况下,文件看起来像:

{
   "graph": "/test/docker"
}

In order to interact with containers, use the ansible docker_container module : 要与容器交互,请使用ansible docker_container模块

- name: Ensure My docker container is running
  docker_container:
    name: testing
    image: busybox
    state: started
  become: true

Try to avoid doing anything in ansible using the shell module, since it can cause headaches down the line. 尽量避免使用shell模块在ansible中做任何事情,因为它可能导致头痛。

You can also start Docker and other services automatically when booting the machine.也可以在开机时自动启动Docker等服务。 For that you can use the systemd module in Ansible like this:为此,您可以像这样使用 Ansible 中的systemd模块:

- name: Enable docker.service
  systemd:
    name: docker.service
    daemon_reload: true
    enabled: true

- name: Enable containerd.service
  systemd:
    name: containerd.service
    daemon_reload: true
    enabled: true

Reference: here参考: 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM