'How to run python file after docker-compose in a shell script?

I want to run a python file after a docker-compose file, which contains localstack. This is how I am trying:

#!/bin/bash

docker-compose -f docker-compose.yml up
python main.py 

After running the docker-compose file, it does not proceed to run my next command. Can anyone help me to achieve the above?



Solution 1:[1]

The -d argument to docker-compose up will make it detach from the containers and return, so that other commands can run:

#!/bin/bash

docker-compose -f docker-compose.yml up -d
python main.py

Just make sure your other command does not run too early if it relies on the containers.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Klaus D.