connect to Docker container on remote host

Hi,

since Ansible 2.0 it is possible to deploy directly to a docker container via connection=docker. Now I want to create a Role which is starting a Docker container and deploying some stuff to it. Here is an arbitrary example of my current solution:

`

  • name: create docker container
    docker:
    name: mycontainer
    image: my/container
    ports:

  • “2222:22”
    state: running

  • name: add aci_jenkins to inventory
    add_host:
    name: mycontainer
    ansible_connection: docker

  • name: copy jenkins private key
    delegate_to: mycontainer

copy:
content: “{{ ID_RSA }}”
dest: /home/user/.ssh/id_rsa
mode: 0700

`

This approach works quite fine since I deploy the role on my localhost. Because the deletage_to directive is delegating from the ansible machine (my localhost) it will find the docker container started. If I deploy the Role on a remote host, the container will be started on the remote host, but the delegate_to directive will looking for the container on the local host. Currently there is no documentation of the docker connection. Does anybody know how I redirect the docker connection to the remote host I started the container in?

the docker connection plugin will only connect to hosts on the ansible
control machine, it is using the local execution tools to access the
docker instance w/o using ssh.

Thank you for quick reply. Is it possible to pass the -H / --host parameter to the local docker binary, such that you can specify the socket to talk to the (remote) Docker daemon (e.g. tcp://myhost:port/path)?

The current docker connection plugin does not seem to support that
(yet). I suggest opening a github feature request to allow for usage
with the docker daemon.

Is there a possibility to define the command docker is called with? This would solve my problem, since I have created an alias calling the remote Docker daemon. Within the connection/docker.py there is following code:

`

def init(self, play_context, new_stdin, *args, **kwargs):
super(Connection, self).init(play_context, new_stdin, *args, **kwargs)

if ‘docker_command’ in kwargs:
self.docker_cmd = kwargs[‘docker_command’]

`

How can I set the ‘docker_command’ from **kwargs within my Ansible Role (or Playbook)?