docker create a container install ansible code example

Example: run docker container with ansible

# In playbook, use docker_container module

- hosts: database1
  tasks:
  - name: Start docker service
      service: 
        name: docker
        state: started
   - name: Create Postgres Container 
      docker_container: # HERE the module
        name: postgres
        image: postgres:12
        state: started
        recreate: yes # Defines if an existing container should be recreated
        ports: 
          - "5432:5432"
        volumes: 
          - /home/my_volume:/var/lib/postgresql/data
        env:
        	myenv1: ""