0

I'm trying to containerise a service which listens to a Google PubSub queue of urls, processes the data using some ML models and uploads the results to a firestore DB.

Locally it works as expected, however when it comes to building and running the docker container I see some very strange behaviour. When I run the server through:

CMD ["python3", "urlQueueProcessor.py"]

at the end of the Dockerfile, the script starts but doesn't behave as expected. Some console warnings/startup stuff from packages are printed, but it immediately hangs before reaching any of my code. If I try a print statement before my imports it never shows.

What's stranger is that if I enter the container and run the exact same command through the terminal it does exactly what I expect and starts the server. I made a little script to check the environments and when I run it through CMD and terminal they both show the same output.

Has anyone seen this before? Or is there any workaround that I can try? I've tried starting it through a .sh but it didn't make any difference. I've spent around 2 days on this with no luck so any help would be appreciated. Here's the Dockerfile

Cheers.

4
  • can you provide more details? - Dockerfile - how have you connected inside the container? post the exact command Commented Feb 15, 2024 at 17:31
  • I find the container name with docker ps, then use docker exec -it [container_name] /bin/sh (in Windows cmd terminal). I linked the Dockerfile at the end of the post. Commented Feb 15, 2024 at 17:52
  • Does Why doesn't Python app print anything when run in a detached docker container? describe your issue? If not, can you edit the question to include a minimal reproducible example directly in the question and not behind links? Commented Feb 15, 2024 at 18:55
  • @DavidMaze The solutions from that thread actually worked, thank you. I can't believe the server was working all this time but just not able to print the logs. Commented Feb 15, 2024 at 19:46

1 Answer 1

1

The thread that @DavidMaze suggested turned out to be the same issue; the script was running correctly but none of my print statements were being shown in the logs (also making debugging attempts invisible). Specifically, all I needed to do was change:

CMD ["python3", "urlQueueProcessor.py"]

to

CMD ["python3", "-u", "urlQueueProcessor.py"]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.