[英]how to run docker compose using docker python sdk
I would like to run docker-compose via python docker sdk.我想通过 python docker sdk 运行 docker-compose。 However I couldn't find any reference on how to achieve this using these reference Python SDK ?
但是我找不到任何关于如何使用这些参考Python SDK来实现这一点的参考? I could also use subprocess but I have some other difficulty while using that.
我也可以使用子流程,但是在使用它时我还有其他一些困难。 see here docker compose subprocess
见这里docker 撰写子流程
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.
我能给出的最好的方法是简化 docker-compose 逻辑。 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.
例如,您有一个带有网络和服务的 YAML 文件 - 使用 Python Docker ZF20E3C5E603C0AB3D3675D 分别创建它们并连接6个容器网络。
It gets cumbersome, but eventually you can get things working that way from Python.它变得很麻烦,但最终你可以从 Python 开始。
I created a package to make this easy: python-on-whales我创建了一个 package 来简化此操作: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/ You can find the source for the package in my GitHub repository: https://gabrieldemarmiesse.github.io/python-on-whales/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.