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?
Compose uses the project name to create unique identifiers for all of a project's containers and other resources. To run multiple copies of a project, set a custom project name using the -p command line option or the COMPOSE_PROJECT_NAME environment variable.
Using Multiple Docker Compose Files Use multiple Docker Compose files when you want to change your app for different environments (e.g., dev, staging, and production) or when you want to run admin tasks against a Compose application.
If you want to force Compose to stop and recreate all containers, use the --force-recreate flag. If the process encounters an error, the exit code for this command is 1 . If the process is interrupted using SIGINT (ctrl + C) or SIGTERM , the containers are stopped, and the exit code is 0 .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With