2

I have Flask application container which has to run on port 5000.

I also have a background process which is related to queue. This process has an infinite loop which is why I want to run it in background.

I'm using docker-compose.yml file for creating container. For now, I'm able to run only one command which is to make the flask server up.

flask run --host=0.0.0.0 --port 5000. I'm using the command option in docker-compose .

This is the command I want to run in background python app/workload/services/queue_services.py > qlog.txt.

When I put the background command first in command, the server is not coming up and I'm only seeing the output from background script.

When I put the flask run command first, the background script is not starting at all.

Is there any proper way to run these two commands on container start up?

Underoos
  • 4,708
  • 8
  • 42
  • 85
  • 1
    Generally you’d run the other command in a second container. Is there any specific reason it must be in the same container? – David Maze Oct 03 '19 at 15:05
  • As per the requirement that I'm working on, they have to be on a same container. – Underoos Oct 03 '19 at 16:24

3 Answers3

3

create a script.sh

#!/bin/bash
python app/workload/services/queue_services.py > qlog.txt &
flask run --host=0.0.0.0 --port 5000

and set it as your command

LinPy
  • 16,987
  • 4
  • 43
  • 57
0

Try Adding

CMD ["gunicorn", "--bind=0.0.0.0:5000", "--workers=1", "wsgi"]

in DockerFile

Stefano
  • 4,730
  • 1
  • 20
  • 28
sandeep
  • 1
  • 1
0

Another approach could be to use a program like supervisord. This way, we can scale it to multiple services without ever modifying the Dockerfile

https://docs.docker.com/config/containers/multi-service_container/

I have compiled an image with supervisord and jre. https://hub.docker.com/r/palashgoel/supervisord-jre

Palash Goel
  • 624
  • 6
  • 17