I created a custom command in django and I want to use a docker-compose command in it. I use a subprocess as follow:
class Command(BaseCommand):
def handle(self, *args, **options):
data = open_file()
os.environ['DATA'] = data
command_name = ["docker-compose ", "-f", "docker-compose.admin.yml", "up"]
popen = subprocess.Popen(command_name, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True)
return popen
when I do it I get a FileNotFoundError:
FileNotFoundError: [Errno 2] No such file or directory: 'docker-compose ': 'docker-compose
Is it even possible to use docker-compose inside of a command ? It feels like I am missing something.
Thank you !
I see 2 possible things.
Your docker compose should run in background, so, you should add
-doption at the end of the command:docker-compose -f docker-compose.admin.yml up -dBest practice is start docker compose in background and you can take output with popen executing
docker-compose -f docker-compose.admin.yml logsYou can also run docker-compose services and get interactive output, defining
stdin_open: truein your yml file.os.getcwd()and comparing it to docker-compose.admin.yml path.