0

I have a python script that launches multiple programs in different screen sessions (gnu screen: terminal multiplexer) and exits.

The screen sessions keep running in the background.

Everything works fine when I run the script directly on my host machine.

Now, I dockerized the entire thing. But docker containers exit after the script finishes.

docker run -d myimage

After reading a bit, I realized that this is the normal behavior of docker. if no foreground process is running it will exit.

But I want to keep the docker container up, what should I do?

I saw, that running with -it flag, keeps it up. But I want to detach from the container, yet keep it up.

aahnik
  • 1,661
  • 1
  • 11
  • 29
  • 1
    Create a foreground process in python that never ends.. depending on your program maybe a while True loop in main just calling asyncio.sleep(number) or create a thread with while True: time.sleep(number) – araisch May 07 '21 at 09:05
  • exactly, i have done that only. i believe this while true infinite loop, does not consume much cpu and memory, and the background processes will not be affected ? – aahnik May 07 '21 at 09:14
  • 1
    Hard to tell for sure without any knowledge about your source code. time.sleep blocks your thread but not the process. If you have a thread just doing the idle stuff it doesn't hurt no one. CPU and MEM are not used at all. You can monitor it with htop or something.. – araisch May 07 '21 at 09:29
  • Can you replace your launcher script entirely with Compose; instead of launching subprocesses in separate Screen windows, have Compose launch them in separate Docker containers? – David Maze May 07 '21 at 09:43
  • hi david and araisch can you tell whats best for me https://github.com/aahnik/telewater please see the entrypoint.py and Dockerfile, thank you – aahnik May 07 '21 at 13:37

0 Answers0