ANSIBLE.DOCKER(3)

NAME
docker - manage docker containers

DESCRIPTION

Manage the life cycle of docker containers.

OPTIONS

command
    Set command to run in a container on startup

count
    Set number of containers to run (default: yes

detach
    Enable detached mode on start up, leaves container running in background (default: yes

dns Set custom DNS servers for the container

docker_url
    URL of docker host to issue commands to (default: unix://var/run/docker.sock)

env Set environment variables (e.g. env="PASSWORD=sEcRe7,WORKERS=4")

hostname
    Set container hostname

image
    Set container image to use(required)

lxc_conf
    LXC config parameters, e.g. lxc.aa_profile:unconfined

memory_limit
    Set RAM allocated to container (default: 256MB)

password
    Set remote API password

ports
    Set private to public port mapping specification (e.g. ports=22,80 or ports=:8080 maps 8080 directly to host)

privileged
    Set whether the container should run in privileged mode

state
    Set the state of the container Choices: present,stopped,absent,killed,restarted. (default: present)

username
    Set remote API username

volumes
    Set volume(s) to mount on the container

volumes_from
    Set shared volume(s) from another container.

EXAMPLES
Start one docker container running tomcat in each host of the web group and bind tomcat's listening port to 8080
on the host:
- hosts: web
  sudo: yes
  tasks:
  - name: run tomcat servers
    docker: image=centos command="service tomcat6 start" ports=:8080
The tomcat server's port is NAT'ed to a dynamic port on the host, but you can determine which port the server was
mapped to using docker_containers:
- hosts: web
  sudo: yes
  tasks:
  - name: run tomcat servers
    docker: image=centos command="service tomcat6 start" ports=8080 count=5
  - name: Display IP address and port mappings for containers
    debug: msg={{inventory_hostname}}:{{item.NetworkSettings.Ports['8080/tcp'][0].HostPort}}
    with_items: docker_containers
Just as in the previous example, but iterates over the list of docker containers with a sequence:
- hosts: web
  sudo: yes
  vars:
    start_containers_count: 5
  tasks:
  - name: run tomcat servers
    docker: image=centos command="service tomcat6 start" ports=8080 count={{start_containers_count}}
  - name: Display IP address and port mappings for containers
    debug: msg={{inventory_hostname}}:{{docker_containers[{{item}}].NetworkSettings.Ports['8080/tcp'][0].HostPort}}"
    with_sequence: start=0 end={{start_containers_count - 1}}
Stop, remove all of the running tomcat containers and list the exit code from the stopped containers:
- hosts: web
  sudo: yes
  tasks:
  - name: stop tomcat servers
    docker: image=centos command="service tomcat6 start" state=absent
  - name: Display return codes from stopped containers
    debug: msg="Returned {{inventory_hostname}}:{{item}}"
    with_items: docker_containers

AUTHOR
Cove Schneider

SEE ALSO
ansible(1), http://ansible.github.com/modules.html#docker