简体   繁体   English

如何运行 docker 撰写使用 docker python sdk

[英]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.

相关问题 如何使用特定 GPU 运行 docker 容器 Docker SDK for Python - How to run a docker container with specific GPUs using Docker SDK for Python 如何使用docker-compose运行Python Django和Celery? - How to run Python Django and Celery using docker-compose? 如何在Python SDK中运行docker命令 - How to run docker command in Python SDK 如何在 docker-compose 之后在 shell 脚本中运行 python 文件? - How to run python file after docker-compose in a shell script? python docker sdk 如何在containers.run 中运行多个命令 - python docker sdk how to run multiple commands in containers.run 使用 docker compose 运行两个 python 脚本 - run two python scripts with docker compose 如何运行 FastAPI 并使用 Docker 撰写文件连接到 MySQL 数据库? - How to run FastAPI and connect to a MySQL database using a Docker compose file? Docker 无法打开文件以在使用 django 的容器中运行 python 应用程序,使用 ZBAEDB53E845AE71F13945FCC00572 - Docker can't open file to run the python application in a container with django using docker-compose Python docker sdk 如何在containers.run中设置cpu计数 - Python docker sdk how to set cpu count in containers.run 如何使用Docker / Kubenertes正确运行Python? - How to properly run Python using Docker/Kubenertes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM