Ansible docker_container gives “Error getting network id”

I’m running an ansible playbook from an ansible control located in a docker container. The playbook should create another docker container and attach it to a bridge network. The docker daemon is located on the host machine from which I launched the ansible control container.

My playbook is simple and I can ansible ping the host:

  • How to get the status of Docker Image Tag that lies in a private registry
  • How can we add capabilities to a running docker container?
  • How does docker map host partitions?
  • Ansible and docker-py
  • Windows Containers : Unable to ping containers created with transparent network from other hosts
  • docker containers share unix abstract socket or dbus
  •   - 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 
    

    I’m getting this error:

    “msg”: “Error getting network id for my-network – (‘Connection
    aborted.’, error(104, ‘Connection reset by peer’))”

    UPDATE 1/19/2017:

    I can now do this. The provsioning playbook looks something like this:

    - 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 }}"
    

    Notes:

    • First I had to set up .ssh between ansible-master and the docker containers I want to provision, which I do in the dockerfiles.
    • docker-host is defined in inventory file
    • register: ansible_docker_container just returns some facts from docker_container. It can be printed later in a debug task, but its not very helpful.

    docker-inst-setup.yml looks something like:

    inst_types:
      - {cont_name: "gf-das", cont_count: 1}
      - {cont_name: "gf-build-node", cont_count: 1}
    

    The process is complicated but I wrote it all up in this blog article. I hope this helps.

  • Is there any solution to execute binary in container that mount from host?
  • Bash script wait depended commands processes
  • Docker won't change VHD location
  • Create docker image to run selenium tests on different browser versions
  • Multiple docker servers using same containers
  • Visual Studio publish to custom Docker container fails due to non-existent Dockerfile directory
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.