0

Using docker compose I've created a container for my MySQL DB and one for my Python script. When I use the command docker compose up, my images are built for my Python app container and my MySQL DB container, and the python script is run. After execution, the shell just hangs since MySQL server is still running and my script has completed execution. How can I either stop the MySQL server after my script runs, or re-run my script while the MySQL server continues to run?

1 Answer 1

1

When running docker-compose up, your current shell will display all the logs from all the containers defined in the docker-compose.yaml file. Also if you terminate the command with cmd + c in MacOS, all the containers will stop running.

As a result, this gives you the impression that the shell just hangs while everything is still running as normal.

What you want in this case is to let the containers continue to run in the background (detached mode)

docker-compose up --detach

The MySQL server will now continue to run until you stop it with docker-compose down.

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

2 Comments

Thank you. IN that case, how do I re-run my script when I want to (eg every 24hours)? Do I need to do docker-compose up each time or is there a better alternative?
Your best bet is to 1) set the container with the script to restart: always so it will always be up while docker is up. 2) set the entrypoint and command to tail -f /dev/null so that the container will not be terminated half-way. 3) Install cronjob inside the docker container and configure it to run every 24 hours.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.