19

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?

7
  • 3
    docker-compose is a Python script :) Commented Dec 9, 2018 at 22:23
  • 1
    github.com/docker/compose/blob/master/compose/cli/main.py#L182 Commented Dec 9, 2018 at 22:26
  • 1
    ah! i didn't know that, but maybe I am not very clear about what I want to do. Let say I have a flask application, I also have some docker-compose scripts, and I want to execute them from my application. Isn't there someway to do that? Commented Dec 9, 2018 at 22:33
  • 3
    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 Commented Dec 9, 2018 at 22:36
  • 2
    docker run is not the same as docker-compose - it's two different projects that are only marginally linked. Please reopen the question. Commented Jun 19, 2021 at 17:55

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

4 Comments

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 :)
This does not the answer directly. How to actually get it done? This does not say.
@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).
Was looking for actual code that does that. I wrote it myself already.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.