dhanupreeth
dhanupreeth

Reputation: 33

how to mount the nginx docker container into host using Ansible Playbook?

I want to deploy a nginx docker container in my server I used Capistrano before now am migrating everything into Ansible my playbook was working fine expect mounting the container volume into host see my code below

vars.yml

image: nginx:latest
name: Nginx
src_port: 80
dest_port: 80
src_vol: /var/www/nginx
dest_vol: /etc/nginx
privileged: true

main.yml

 - name: include variables
   include_vars: vars.yml
 - name: Checking running Docker Container
   become: yes
   shell: docker ps -a
 - name: Starting the Nginx Docker Container
   become: yes
   docker:
    name: "{{ name }}"
    image: "{{ image }}"
    state: started
    restart_policy: always
    ports:
     - "{{ src_port }}:{{ dest_port }}"
    volumes: "{{ src_vol }}:{{ dest_vol }}:rw" 

Docker version - 17.03.1-ce-rc1 / API - 1.27 (Control Machine) and Target Machine Docker Version - 17.03.0-ce / API - 1.26

Upvotes: 0

Views: 1126

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68289

  1. volumes parameter is a list, use:

    volumes:
      - "{{ src_vol }}:{{ dest_vol }}:rw"
    
  2. docker module is deprecated. Use docker_container.

Upvotes: 1

Related Questions