Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write an Ansible playbook with Docker-compose

Tags:

docker

ansible

Please help, I have the docker-compose file below, and I want to write an Ansible playbook that runs the docker-compose file on localhost and a remote target.

   version: '2.0'

services:
weather-backend:
  build: ./backend
  volumes:    #map backend dir and package inside container
    - './backend/:/usr/src/'
    - './backend/package.json:/usr/src/package.json'
  #ports:
 #  - "9000:9000" #expose backend port - Host:container
  ports:
     - "9000:9000"
  command: npm start


weather-frontend:
  build: ./frontend
  depends_on:
    - weather-backend
  volumes:
    - './frontend/:/usr/src/'
    - '/usr/src/node_modules'
  ports:
    - "8000:8000" #expose ports -Host:container
  environment:
    NODE_ENV: "development"
like image 265
Larry Avatar asked Jul 07 '17 03:07

Larry


1 Answers

Since Ansible 2.1, you can have a look at the docker_compose, which can read directly a docker-compose.yml

playbook task:

- name: run the service defined in my_project's docker-compose.yml
  docker_compose:
    project_src: /path/to/my_project
like image 66
VonC Avatar answered Nov 01 '22 18:11

VonC