##### SUMMARY

`docker_container` module often fails because removal of `auto_remove: yes` takes some time. I had the same problem before with shell scripts since `docker stop` returns immediately but container removal takes some time to finish. Until removal is finished, no new container with the same name can be created.

The error message is:

    Error creating container: 409 Client Error: Conflict ("Conflict. The container name "/MYCONTAINER" is already in use by container "HASH". You have to remove (or rename) that container to be able to reuse that name.")

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
docker_container

##### ANSIBLE VERSION
```
ansible 2.9.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/USER/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17rc1 (default, Oct 10 2019, 10:26:01) [GCC 9.2.1 20191008]

```

##### CONFIGURATION
_no changes_

##### OS / ENVIRONMENT
Ubuntu 19.10


##### STEPS TO REPRODUCE

0. Run playbook to create container
0. Apply many changes to the file system
0. Run playbook again

```yaml
docker_container:
  name: SOMETHING
  image: SOMETHING
  state: started
  detach: yes
  recreate: yes
  autoremove: yes
```

##### EXPECTED RESULTS
Wait for removal before trying to create a new container.


##### ACTUAL RESULTS
Command fails.

```
Error creating container: 409 Client Error: Conflict ("Conflict. The container name "/MYCONTAINER" is already in use by container "HASH". You have to remove (or rename) that container to be able to reuse that name.")
```


'Please note that docker_container handles networks slightly different than docker CLI. '
            'If you specify networks, the default network will still be attached as the first network. '
            '(You can specify purge_networks to remove all networks not explicitly listed.) '
            'This behavior will change in Ansible 2.12. You can change the behavior now by setting '
            'the new `networks_cli_compatible` option to `yes`, and remove this warning by setting '
            'it to `no`',
            version='2.12'
        )
    if client.module.params['networks_cli_compatible'] is True and client.module.params['networks'] and client.module.params['network_mode'] is None:
        client.module.deprecate(
            'Please note that the default value for `network_mode` will change from not specified '
            '(which is equal to `default`) to the name of the first network in `networks` if '
            '`networks` has at least one entry and `networks_cli_compatible` is `true`. You can '
            'change the behavior now by explicitly setting `network_mode` to the name of the first '
            'network in `networks`, and remove this warning by setting `network_mode` to `default`. '
            'Please make sure that the value you set to `network_mode` equals the inspection result '
            'for existing containers, otherwise the module will recreate them. You can find out the '
            'correct value by running "docker inspect --format \'{{.HostConfig.NetworkMode}}\' <container_name>"',
            version='2.14'
        )
    try:
        cm = ContainerManager(client)
        client.module.exit_json(**sanitize_result(cm.results))
    except DockerException as e:
        client.fail('An unexpected docker error occurred: {0}'.format(e), exception=traceback.format_exc())
    except RequestException as e:
        client.fail('An unexpected requests error occurred when docker-py tried to talk to the docker daemon: {0}'.format(e), exception=traceback.format_exc())
if __name__ == '__main__':
    main()