How To Run Any Python App in Docker with Docker Compose
Running docker-compose from python - Stack Overflow
how to run docker compose using docker python sdk - Stack Overflow
Tutorial/examples for using docker-compose code as a python module in a python script
Videos
» pip install docker-compose
I have created a small article and video with a tutorial for beginners that will help them run any Python app in Docker with docker-compose:
https://www.bitdoze.com/docker-run-python/
I created a package to make this easy: 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/
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. 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.
It gets cumbersome, but eventually you can get things working that way from Python.
» pip install docker-composer
I have a RabbitMQ server and a script for creating my exchanges & queues. Here is what my docker-compose.yml looks like:
version: "3.9"
services:
rabbitmq:
image: rabbitmq:3.8-management-alpine
ports:
- 5672:5672
- 15672:15672
restart: always
volumes:
- ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
- ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
Assuming I have a file called migration.py on my project's root folder, how do I run this script after the rabbitmq service finishes starting up?