### Install Specific Docker SDK Version for Python 2.7 Source: https://github.com/ansible-collections/community.docker/blob/main/docs/docsite/rst/scenario_guide.rst For Python 2.7, install a specific version of the Docker SDK for Python (between 2.0.0 and 4.4.4) as support was removed in later versions. Avoid installing both 'docker' and 'docker-py'. ```console $ pip install 'docker==4.4.4' ``` -------------------------------- ### Start Docker Container Source: https://github.com/ansible-collections/community.docker/blob/main/docs/docsite/rst/scenario_guide.rst Starts a Docker container with specified image, command, and name. Includes options for cleanup, detached mode, and capturing output logs. ```yaml - name: Start container community.docker.docker_container: cleanup: true command: python --version detach: false image: python:3.12 name: my-python-container output_logs: true ``` -------------------------------- ### Install Docker SDK for Python Source: https://github.com/ansible-collections/community.docker/blob/main/docs/docsite/rst/scenario_guide.rst Install the Docker SDK for Python using pip. This is required for most community.docker modules and plugins. ```console $ pip install docker ``` -------------------------------- ### Configure Docker Module Defaults Source: https://github.com/ansible-collections/community.docker/blob/main/docs/docsite/rst/scenario_guide.rst Set default connection options for Docker modules, including host, TLS settings, and timeouts. This configuration applies to all Docker modules within the play. ```yaml hosts: localhost gather_facts: false module_defaults: group/community.docker.docker: # Select Docker Daemon on other host docker_host: tcp://192.0.2.23:2376 # Configure TLS tls: true validate_certs: true tls_hostname: docker.example.com ca_path: /path/to/cacert.pem # Increase timeout timeout: 120 tasks: - name: Pull image community.docker.docker_image_pull: name: python tag: 3.12 - name: Start container community.docker.docker_container: cleanup: true command: python --version detach: false image: python:3.12 name: my-python-container output_logs: true - name: Show output ansible.builtin.debug: msg: "{{ output.container.Output }}" ``` -------------------------------- ### Display Container Output Source: https://github.com/ansible-collections/community.docker/blob/main/docs/docsite/rst/scenario_guide.rst Uses the ansible.builtin.debug module to display the output captured from a Docker container. ```yaml - name: Show output ansible.builtin.debug: msg: "{{ output.container.Output }}" ``` -------------------------------- ### Pull Docker Image Source: https://github.com/ansible-collections/community.docker/blob/main/docs/docsite/rst/scenario_guide.rst Pulls a Docker image with a specified name and tag using the community.docker.docker_image_pull module. ```yaml - name: Pull image community.docker.docker_image_pull: name: python tag: 3.12 ``` -------------------------------- ### Use Module Defaults Group in Playbook Source: https://github.com/ansible-collections/community.docker/blob/main/docs/docsite/rst/scenario_guide.rst Configure common parameters for Docker modules using the 'community.docker.docker' module defaults group in an Ansible playbook. This avoids repetitive parameter specification. ```yaml --- - name: Pull image and start the container ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.