module docker : dynamic port binding problem

Hello

Ansible 1.9 - docker-py 0.71 - docker version 1.4.1

I’m trying to do in a playbook this docker command line

docker run --name projetx -d -v /Users/hleclerc/tmp/data/projetx/mysql:/var/lib/mysql -p :3306 -e MYSQL_ROOT_PASSWORD=pwd projetx/mysql

docker ps :

4876cb21a372 projetx/mysql:latest "/usr/local/bin/run" 4 seconds ago Up 3 seconds 0.0.0.0:49193->3306/tcp projetx
A dynamic port is allocated

Here is the playbooks :

1:

`

  • name: Starting MySQL container
    docker:
    detach: true
    image: “projetx/mysql”
    name: “projetx”
    ports: “::3306”
    env: “MYSQL_ROOT_PASSWORD=pwd”
    volumes:
  • “/Users/hleclerc/tmp/data/projetx/mysql:/var/lib/mysql”

`

With this syntax if i do a docker ps :

f84b89180678 projetx/mysql:latest "/usr/local/bin/run" About a minute ago Up About a minute 3306/tcp

if i change ports with

ports: 3306

a docker ps will display

6cb9843603f7 projetx/mysql:latest "/usr/local/bin/run" 8 seconds ago Up 7 seconds 0.0.0.0:0->3306/tcp

if i change ports with ‘:3306’ i get this error from ansible

bind = (‘0.0.0.0’, int(parts[0]))

ValueError: invalid literal for int() with base 10: ‘’

How can i have a correct behaviour ?

in advance thanks

remove the colon's from the port setting

ports: 3306

Hello

If i do it i’ve this

ports: 3306

a docker ps display

6cb9843603f7 projetx/mysql:latest "/usr/local/bin/run" 8 seconds ago Up 7 seconds 0.0.0.0:0->3306/tcp

This not good i should have 0.0.0.0:someDynamicPort->3306 and not 0

For information with docker-py :

`

from docker.client import Client
from docker.utils import kwargs_from_env
kwargs = kwargs_from_env()
kwargs[‘tls’].assert_hostname = False
client = Client(**kwargs)
container_id = client.create_container(image=“busybox”, ports=[3306] , command=“sleep 30000000”)
client.start(container_id, port_bindings={3306: (‘127.0.0.1’,{})})

`

give me a correct behaviour

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 513db4e06837 busybox:latest "sleep 30000000" 3 seconds ago Up 3 seconds 127.0.0.1:49154->3306/tcp sad_mclean

The problem is somewhere in docker module / parse

Finally i make it works you need both expose and ports parameters

`

  • name: Starting MySQL container
    docker:
    detach: true
    expose**: 3306**
    publish_all_ports: true
    image: “projetx/mysql”
    name: “projetx”
    ports**: 3306**
    debug: true
    env: “MYSQL_ROOT_PASSWORD=password”
    volumes:
  • “/Users/hleclerc/tmp/data/projetx/mysql:/var/lib/mysql”
    docker_url: “http://192.168.59.103:2375
    state: present
    register: out
    `

f5d49bd72ac0 projetx/mysql:latest "/usr/local/bin/run" 3 minutes agoUp 3 minutes **0.0.0.0:49155->3306**/tcp projetx

ttms