How to run python script running when django server starts

97 Views Asked by At

How to run python script running when django server starts. For example, I have a python kafka script , this script should be running continously when django server starts. when i give two commands in Dockerfile like:

CMD ["python", "manage.py","runserver","0.0.0.0:8443"]
CMD [ "python", "./consumer.py"]

only the latest cmd it is picking up.
Any idea how to start python script and django server using single cmd.

how to start python script and django server using single cmd.

1

There are 1 best solutions below

0
On

In your Dockerfile, add a line to copy a custom startup script into the container. For example:

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

Create a file named entrypoint.sh and add the following content:

#!/bin/bash
python manage.py runserver 0.0.0.0:8443 &

python consumer.py

tail -f /dev/null

In your Dockerfile, use the following CMD instruction:

CMD ["/entrypoint.sh"]