merll / docker-fabric

Integration of Docker deployments into Fabric.
MIT License
79 stars 10 forks source link

task list_containers does not return anything #2

Closed kenden closed 9 years ago

kenden commented 9 years ago

The task list_containers does not list any containers:

$ echo "from dockerfabric import tasks as docker" > fabfile.py $ fab -H 10.0.101.133 docker.list_containers [10.0.101.133] Executing task 'docker.list_containers' [10.0.101.133] Id Names Image Command Ports Status Created

Done.

Note: list images is fine $ fab -H 10.0.101.133 docker.list_images [10.0.101.133] Executing task 'docker.list_images' [10.0.101.133] Id RepoTags ParentId Created VirtualSize Size 1183a43c2e94 stylight/ws-solr:latest 80ef0e18de7e 2015-02-27T12:39:25 1454511143 0 45bb9005020b stylight/wildfly:latest ec0bddcfa096 2015-02-11T09:24:48 1288633198 0

Done.

There IS a container runnning: $ ssh 10.0.101.133 Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-46-generic x86_64)

$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b6a28a641321 stylight/ws-solr:12 "/bin/sh -c '/usr/lo 2 days ago Up 8 hours 9999/tcp, 8787/tcp, 0.0.0.0:8080->8080/tcp, 0.0.0.0:9990->9990/tcp solr

kenden commented 9 years ago

The problem is that: $ fab -H 10.0.101.133 docker.list_containers does not return the containers on 10.0.101.133, but the containers on the local machine. There is no container on the local machine. (but the same images are present).

The fact that the command returns:

[10.0.101.133] Executing task 'docker.list_containers'

is confusing. It actually does:

[localhost] Executing task 'docker.list_containers'

Shouldn't -H set env.docker_base_url ?

$ fab --help |grep HOSTS
  -H HOSTS, --hosts=HOSTS
merll commented 9 years ago

Yes, indeed, the log output is misleading.

Unfortunately setting the URL from the Fabric host would not be sufficient to get a connection. The local Docker client cannot directly access the remote service via Fabric's SSH channel. There are two connection methods: Either the Docker service is configured to allow connections through a local TCP port, or (preferably) socat is used for forwarding traffic from the SSH channel to the socket. In both cases, env.docker_base_url and env.docker_tunnel_remote_port need to be set.

The different behavior sets of the client are documented here, but I agree using Fabric's host in case no other docker_base_url is set explicitly would make sense.

This needs some more consideration in order to make the behavior non-ambiguous, but I will look into it.

kenden commented 9 years ago

Thanks.

With my fabfile.py having the following,

from dockerfabric import tasks as docker

from fabric.api import env
env.docker_base_url = '/var/run/docker.sock'
env.docker_tunnel_remote_port = 2224

it works (using socat).

Maybe make those values default? In the doc https://docker-fabric.readthedocs.org/en/latest/installation.html is says "The tool Socat is needed (...)", so maybe assuming socat will be used should be default.

Or I suggest adding more examples in the doc about setting those variables (with and without socat).

merll commented 9 years ago

Docs and behavior have been improved with the latest release. The setup is more clearly explained in the installation guide now, and for connections to the default socket it is no longer necessary to set the base url.

Thank you for the feedback!