我需要使用以下几个端口映射启动docker容器:

- name: Run My container
  docker_container:
    name: "MyContainer"
    image: "MyImage"
    state: present
    pull: true
    restart_policy: always
    published_ports:
      - 1200:1200
      - 1201:1201
      - 1202:1202
      - 1203:1203
      .
      .
      .
      - 1300:1300

我想要做的是将Ansible脚本运行为:
- name: Run My container
  docker_container:
    name: "MyContainer"
    image: "MyImage"
    state: present
    pull: true
    restart_policy: always
    published_ports:
      - 1200-1300:1200-1300

虽然,这不起作用,但Ansible会给我以下错误消息:
File \"/tmp/ansible_8zDYC9/ansible_module_docker_container.py\", line 987, in _parse_publish_ports\r\n container_port = int(parts[-1])\r\nValueError: invalid literal for int() with base 10: '1200-1300'
是否可以在同一行中映射主机和容器之间的多个端口?

PS:我正在使用Ansible 2.3

最佳答案

我不确定是否有结论,但是您需要将端口设置为双引号,如下所示:
“1200-1300:1200-1300”

关于docker - 启动Docker容器的几个端口,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49815722/

10-16 17:46