我正在一个位于码头工人容器中的ansible控件中运行一个ansible playbook。该剧本应创建另一个泊坞窗容器并将其连接到桥接网络。 docker守护程序位于主机上,我从中启动了ansible控件容器。
我的剧本很简单,我可以回答主持人:
- hosts: docker
become: myuser
connection: local
gather_facts: no
tasks:
- name: Start Node container, connect to network
docker_container:
name: node1
hostname: node1
docker_host: tcp://172.18.0.1:2375
image: ubuntu-java
state: started
tty: yes
detach: yes
restart_policy: on-failure
networks:
- name: my-network
我收到了这个错误:
“msg”:“获取my-network的网络ID时出错 - ('连接 中止。',错误(104,'由同行重置连接'))“
更新1/19/2017:
我现在可以这样做了。推荐剧本看起来像这样:
- hosts: docker-host
vars_files:
- ~/resources/vars/docker-inst-setup.yml
tasks:
- name: debug check
debug:
msg: "container is {{ item.cont_name }}"
with_items: "{{ inst_types }}"
- name: Start container, connect to network
become: true
become_user: "{{ ansible_user_id }}"
docker_container:
name: "{{ item.cont_name }}"
hostname: "{{ item.cont_name }}"
image: gf-node:latest
state: started
tty: yes
detach: yes
restart_policy: on-failure
network_mode: bridge
volumes: /home/me/.ssh
volumes_from: ansible-master
register: ansible_docker_container
with_items: "{{ inst_types }}"
注意:
docker-inst-setup.yml看起来像:
inst_types:
- {cont_name: "gf-das", cont_count: 1}
- {cont_name: "gf-build-node", cont_count: 1}
这个过程很复杂,但我在this blog article写了一遍。我希望这会有所帮助。