如何通过ansible在docker_image中设置--network=host

问题描述 投票:0回答:2

我想用 ansible 剧本替换这个命令

'docker build -q --network host -t "ubuntu" . '

我一直在浏览ansible的docker_image模块,但无法弄清楚。知道如何进一步进行吗?

提前致谢。

ansible docker-compose ansible-2.x
2个回答
0
投票

距离您最近的地方是:

---
- name: build the image
  docker_image:
    name: docker
    tag: ubuntu
    path: "/yourpath"
    state: present

对于 --network 主机,在 Github 中打开了一个请求来获取它。


0
投票

您只需将

network_mode: host
添加到您的
docker_container
任务即可。这是一个工作示例:

---
- name: deploy whoami
  hosts: docker01
  become: true

  tasks:
    - name: install whoami server
      docker_container:
        name: whoami
        image: traefik/whoami
        state: started
        recreate: true
        network_mode: host
© www.soinside.com 2019 - 2024. All rights reserved.