Use Ansible

Note: Please note this is a community contributed installation path.

Requirements

To use this guide you’ll need a working installation of Ansible version 2.1.0 or later.

Requirements on the host that will execute the module:

python >= 2.6
docker-py >= 1.7.0
Docker API >= 1.20

Installation

The docker_container module is a core module, and will ship with Ansible by default.

Usage

Task example that pulls the latest version of the nginx image and runs a container. Bind address and ports are in the example defined as a variable.

---
- name: nginx container
  docker:
    name: nginx
    image: nginx
    state: reloaded
    ports:
    - "::"
    cap_drop: all
    cap_add:
      - setgid
      - setuid
    pull: always
    restart_policy: on-failure
    restart_policy_retry: 3
    volumes:
      - /some/nginx.conf:/etc/nginx/nginx.conf:ro
  tags:
    - docker_container
    - nginx
...

Documentation

The documentation for the ansible_container module is present at docs.ansible.com.

Documentation covering Docker images, networks and services is also present at docs.ansible.com.

© 2017 Docker, Inc.
Licensed under the Apache License, Version 2.0.
Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.
Docker, Inc. and other parties may also have trademark rights in other terms used herein.
https://docs.docker.com/v1.12/engine/admin/ansible/