0

I have a python program that must run in a docker container. When I execute the program in my workspace the program run well. I made a custom Dockerfile from a python image, this image have the same packages in the same version that I have in my workspace. When I run the container using compose the container starts but when I call a specific function the program seems not to run. I put a print before this function call and the print works only when I comment the func call (the func call is after the print), when I call the function the print don't works.

My dockerfile:

FROM python:3.8.5-slim

RUN apt update \
    && apt upgrade -y\
    && apt install -y libsm6 libxext6 libxrender-dev libglib2.0-0 \
    && pip install redis==3.5.3 opencv-contrib-python==4.2.0.32 imutils==0.5.3 scikit-image==0.17.2 \
    && mkdir src
    
WORKDIR /src

CMD ["python"]

My compose:

version: '3.1'  

services:  
  redis:
    image: 'redis:alpine'
    command: redis-server --requirepass 123
    ports:
      - '6379:6379'

  doorState-peopleCounter:
    build:
      context: .
      dockerfile: Dockerfile
    image: custom
    volumes:
      - /media/jose/Arquivos/Argos/rasp-services/movementdetectionwindowsdoor:/src
    command: ["python", "Tracker.py"]

With this code the print doesn't works:

print('[INFO] - Iniciando monitoramento da porta')
tracking.count(source='videos/subindo.mp4')

When I comment the func call the print works:

print('[INFO] - Iniciando monitoramento da porta')
#tracking.count(source='videos/subindo.mp4')
django
  • 43
  • 6

3 Answers3

0

I don't know why, but the container logs only show the prints of the program when the python program ends. So the problem was that I wasn't waiting the program finish and the i started to think that the program was not running.

django
  • 43
  • 6
0

Change

FROM python:3.8.5-slim

to

FROM python:3.8.5

You can add regular python, not Slim, it may be large, but it will do the trick.

bguiz
  • 27,371
  • 47
  • 154
  • 243
Ali Gökkaya
  • 408
  • 6
  • 20
0

This is python's output buffering. It's a performance feature. You can disable it with the environment variable PYTHONUNBUFFERED=1 or by running python with the -u flag. You can also call print with the flush keyword argument.

print('[INFO] - Iniciando monitoramento da porta', flush=True)
D Hudson
  • 1,004
  • 5
  • 12