1

I am trying to run two different commands when doing docker-compose up.

My command: parameter looks like:

gunicorn --reload analytics_api:api --workers=3 --timeout 10000 -b :8083 && exec python /analytics/model_download.py

But when I run this the container fails with the error:

gunicorn: error: unrecognized arguments: && exec python /analytics/model_download.py

The second part of the command python /analytics/model_download.py, is used to download some dependencies from a sharedpath to a directory inside the container.

I want to run it while the service is up, not during the build.

What is going wrong here?

Tom J Muthirenthi
  • 3,028
  • 7
  • 40
  • 60
  • Execute the `exec python /analytics/model_download.py` command first and then run the `gunicorn` command – techytushar Dec 04 '19 at 10:29
  • Does this answer your question? [Why can't I use Docker CMD multiple times to run multiple services?](https://stackoverflow.com/questions/23692470/why-cant-i-use-docker-cmd-multiple-times-to-run-multiple-services) – julian Dec 04 '19 at 11:23
  • Can you run the "download" step as a `RUN` step in your Dockerfile? That'd be cleaner and avoid this problem. – David Maze Dec 04 '19 at 11:40
  • @DavidMaze That will make the image huge, and after each retraining, the build should be made, which is not advised – Tom J Muthirenthi Dec 04 '19 at 11:42
  • @julian I want to run it in the docker-compose file while starting the container, not during the build. – Tom J Muthirenthi Dec 04 '19 at 13:56
  • @techytushar when I do so, the container `exited with code 0` – Tom J Muthirenthi Dec 04 '19 at 14:02
  • I think the entrypoint/ CMD in the Dockerfile can be overridden in the manifest. So same logic would apply there. – julian Dec 04 '19 at 14:19

2 Answers2

0

One way can be to have a startup shell script as the command which has both these entries

startup.sh

#start this in background if the other process need not wait for completion
exec python /analytics/model_download.py &
gunicorn --reload analytics_api:api --workers=3 --timeout 10000 -b :8083

while true 
 do
   sleep 5
done
Wander3r
  • 1,801
  • 17
  • 27
0

Adding bash -c before the command solved the problem.

The command value will look like:

bash -c "python model_download.py && gunicorn --reload analytics_api:api -- workers=3 --timeout 10000 -b :8083"

Tom J Muthirenthi
  • 3,028
  • 7
  • 40
  • 60