docker_container:如何添加多个卷

时间:2018-12-04 14:03:18

标签: docker ansible

我正在尝试使用Ansible执行以下Docker命令:

docker run --name soadb_test1 --network=soa_net --ip 172.16.1.10 -d -v $TEST1/SOADB-Volume/u01:/u01/ -v $TEST1/SOADB-Volume/u02:/u02/ -v $TEST1/SOADB-Volume/u03:/u03/ -v $TEST1/SOADB-Volume/u04:/u04/ -v $TEST1/SOADB-Volume/ORCL:/ORCL/  --env-file $ENV_HOME/db.env.list database/enterprise:12.2.0.1

这是我的Ansible脚本:

---
  - name: Create DB container
    docker_container:
      name: "{{ name }}"
      image: "{{ image }}"
      env_file: "{{ env_file }}"
      detach: yes
      volumes:
          - "{{ src_vol }}:{{ dest_vol }}"
          - "{{ src_vol_2 }}:{{ dest_vol_2 }}"
          - "{{ src_vol_3 }}:{{ dest_vol_3 }}"
          - "{{ src_vol_4 }}:{{ dest_vol_4 }}"
          - "{{ src_vol_5 }}:{{ dest_vol_5 }}"
      networks: 
      - name: soa_net
        ipv4_address: "{{ ip }}"

      vars_files:
         - vars.yml

当我运行它时,出现以下错误:

TASK [install_docker_DB : Create DB container] *******************************************************************************************************************************************************************
fatal: [soa_poc]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (docker_container) module: vars_files Supported parameters include: api_version, auto_remove, blkio_weight, cacert_path, cap_drop, capabilities, cert_path, cleanup, command, cpu_period, cpu_quota, cpu_shares, cpuset_cpus, cpuset_mems, debug, detach, devices, dns_opts, dns_search_domains, dns_servers, docker_host, domainname, entrypoint, env, env_file, etc_hosts, exposed_ports, force_kill, groups, hostname, ignore_image, image, init, interactive, ipc_mode, keep_volumes, kernel_memory, key_path, kill_signal, labels, links, log_driver, log_options, mac_address, memory, memory_reservation, memory_swap, memory_swappiness, name, network_mode, networks, oom_killer, oom_score_adj, output_logs, paused, pid_mode, privileged, published_ports, pull, purge_networks, read_only, recreate, restart, restart_policy, restart_retries, security_opts, shm_size, ssl_version, state, stop_signal, stop_timeout, sysctls, timeout, tls, tls_hostname, tls_verify, tmpfs, trust_image_content, tty, ulimits, user, userns_mode, uts, volume_driver, volumes, volumes_from, working_dir"}

我是用错误的方式声明卷吗?

1 个答案:

答案 0 :(得分:1)

您看来vars_files条目的缩进级别不正确-请将其移至其他位置:

---
  - name: Create DB container
    docker_container:
      name: "{{ name }}"
      image: "{{ image }}"
      env_file: "{{ env_file }}"
      detach: yes
      volumes:
          - "{{ src_vol }}:{{ dest_vol }}"
          - "{{ src_vol_2 }}:{{ dest_vol_2 }}"
          - "{{ src_vol_3 }}:{{ dest_vol_3 }}"
          - "{{ src_vol_4 }}:{{ dest_vol_4 }}"
          - "{{ src_vol_5 }}:{{ dest_vol_5 }}"
      networks: 
          - name: soa_net
            ipv4_address: "{{ ip }}"

第一个网络条目的缩进也是错误的。

取决于以上内容是来自剧本文件还是角色,vars_files的位置可能有所不同。如果这是一本剧本,那么vars_files的缩进级别应与tasks相同:

---
- hosts: all
  vars_files:
    - vars.yml
  tasks:
    - name: Create DB container
      docker_container: ...

这与卷无关...