In ansible playbook I need to run docker-compose commands. How can I do it? I need to run command: docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
As mentioned, you can use Ansible to automate Docker and to build and deploy Docker containers. First, you'll need to have Docker SDK for Python installed.
You should copy your Docker Compose files and use docker_compose
module such as:
- name: copy Docker Compose files
copy:
src: files/{{ item }}
dest: /somewhere/yourproject/{{ item }}
loop:
- docker-compose.yml
- docker-compose.prod.yml
# use files parameter to use multiple docker-compose.yml files
- name: deploy Docker Compose stack
docker_compose:
project_src: /somewhere/yourproject
files:
- docker-compose.yml
- docker-compose.prod.yml
At the end I decided to use to use shell module. I think @pierre-b answer is more correct but anyway:
- name: Run container
become: True
shell:
cmd: "docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d"
chdir: /mydir/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With