skip to Main Content

Below is my docker enterypoint.sh file code

#!/bin/bash
set -e

python3 test1.py

gunicorn -b 0.0.0.0:8000 "app:app" --workers=1 --threads=10 --timeout=3600

node /home/test2.js

I want to run test2.js nodejs app after gunicorn service starts because test2.js required to connect with localhost:8000. Please help me with a solution for this

3

Answers


  1. Chosen as BEST ANSWER

    Think the ideal solution will be to deploy 2 different containers using docker-compose, one for gunicorn and another one for test2.js nodejs app.

    But could run test2.js nodejs script after starting gunicorn service using below code by inserting "&" at the end of gunicorn line

    #!/bin/bash
    set -e
    
    python3 test1.py
    
    gunicorn -b 0.0.0.0:8000 "app:app" --workers=1 --threads=10 --timeout=3600 &
    
    node /home/test2.js
    

  2. By default, the next line is only executed after the previous one, but maybe the command ends before the port is active, so you can use a while to check that

    #!/bin/bash
    set -e
    
    python3 test1.py
    
    gunicorn -b 0.0.0.0:8000 "app:app" --workers=1 --threads=10 --timeout=3600
    #
    check=1
    #
    while [ $check -eq 1 ]
    do
      echo "Testing"
      test=$(netstat -nlt | grep "0.0.0.0:8000" &> /dev/null)
      check=$?
      sleep 2
    done
    
    node /home/test2.js
    
    Login or Signup to reply.
  3. Try this :

    #!/bin/bash
    set -e
    
    python3 test1.py
    
    # wait 10 seconds, then run test2.js
    { sleep 10; node /home/test2.js; } &
    
    gunicorn -b 0.0.0.0:8000 "app:app" --workers=1 --threads=10 --timeout=3600
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search