Search code examples
pythonshelldockerdockerfilemultiple-processes

Running Multiple python processes in Docker


I am new to docker, trying to run multiple python processes in docker. Though it's not recommended, however, it should work as suggested here "https://docs.docker.com/engine/admin/multi-service_container/"

My Dockerfile :

FROM custom_image
MAINTAINER Shubham 
RUN apt-get update -y
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["/bin/bash"]
CMD ["start.sh"]

start.sh :

nohup python flask-app.py &
nohup python sink.py &
nohup python faceConsumer.py &
nohup python classifierConsumer.py &
nohup python demo.py &
echo lastLine

run command :

docker run --runtime=nvidia -p 5000:5000 out_image
  • the same shell script worked when I go to terminal and run.
  • tried without nohup, didn't work.
  • tried python subprocess also to start other python processes, didn't work.

Is it possible to run multiple processes without supervisord or docker-compose?

update: not getting any error, only "lastLine" is getting printed and docker container exits.


Solution

  • Your problem is putting everything in background. Your container starts, executes all commands and then exits when CMD process finishes - despite background processes running. Docker does not know that.

    You could try running everything else in background but then

    python demo.py
    

    as it is. This would cause the process to stay alive assuming demo.py does not exit.