如何使用Ansible Playbook将nginx docker容器挂载到主机?

时间:2017-03-25 16:02:26

标签: nginx docker ansible

我想在我的服务器中部署一个nginx docker容器我之前使用过Capistrano我正在将所有内容迁移到Ansible我的playbook工作正常,期望将容器卷安装到主机中,请参阅下面的代码

vars.yml

image: nginx:latest
name: Nginx
src_port: 80
dest_port: 80
src_vol: /var/www/nginx
dest_vol: /etc/nginx
privileged: true

main.yml

 - name: include variables
   include_vars: vars.yml
 - name: Checking running Docker Container
   become: yes
   shell: docker ps -a
 - name: Starting the Nginx Docker Container
   become: yes
   docker:
    name: "{{ name }}"
    image: "{{ image }}"
    state: started
    restart_policy: always
    ports:
     - "{{ src_port }}:{{ dest_port }}"
    volumes: "{{ src_vol }}:{{ dest_vol }}:rw" 

Docker版本 - 17.03.1-ce-rc1 / API - 1.27(控制机器)和目标机器Docker版本 - 17.03.0-ce / API - 1.26

1 个答案:

答案 0 :(得分:1)

  1. volumes参数是一个列表,使用:

    volumes:
      - "{{ src_vol }}:{{ dest_vol }}:rw"
    
  2. docker模块已弃用。使用docker_container