Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run docker compose using docker python sdk

I would like to run docker-compose via python docker sdk. However I couldn't find any reference on how to achieve this using these reference Python SDK? I could also use subprocess but I have some other difficulty while using that. see here docker compose subprocess

like image 580
change198 Avatar asked Sep 06 '26 02:09

change198


2 Answers

I created a package to make this easy: python-on-whales

Install with

pip install python-on-whales

Then you can do

from python_on_whales import docker
docker.compose.up()
docker.compose.stop()
# and all the other commands.

You can find the source for the package in my GitHub repository: https://gabrieldemarmiesse.github.io/python-on-whales/

like image 196
Gabriel de Marmiesse Avatar answered Sep 07 '26 17:09

Gabriel de Marmiesse


I am working on the same issue and was looking for answers, but nothing so far. The best shot I can give it is to simplify that docker-compose logic. For example, you have a YAML file with a network and services - create them separately using Python Docker SDK and connect containers to a network.

It gets cumbersome, but eventually you can get things working that way from Python.

like image 30
Eli Halych Avatar answered Sep 07 '26 15:09

Eli Halych



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!