I am looking for a way to run a docker-compose file from python script. I looked in Docker SDK for python, but i didn't found anything about docker-compose. So, is there a way to run a docker-compose file from python script?
1 Answer
The question was answered by @cricket_007:
It's not a supported use case, nor meant to be used that way. github.com/docker/compose/issues/4542#issuecomment-283191533 You could just use subprocess module to shell out to the commands, or use docker-py directly – cricket_007 Dec 9 '18 at 22:36
And the answer was accepted by the OP:
Ok so, I think the simplest way for me is to use subprocess module. Thanks for your response :) – Nidal
4 Comments
caxcaxcoatl
This was answered as a community wiki entry, in the spirit of meta.stackexchange.com/questions/117251/…. This looks a proper answer for a proper question. If the actual author of the answer put an actual answer, I can remove this one. I just want it to get out of my search results :)
Gulzar
This does not the answer directly. How to actually get it done? This does not say.
caxcaxcoatl
@Gulzar, the answer is: If you want to use docker-compose from Python, you'll have to call it as any other executable, using
subprocess. Why: docker-compose is not supposed to be used as a library (see link).Gulzar
Was looking for actual code that does that. I wrote it myself already.
docker-composeis a Python script :)subprocessmodule to shell out to the commands, or usedocker-pydirectly