dockercroncron-taskportainerdjango-crontab

python don´t excecute when start container with crontab


I try to execute a python when the container start. I use crontab in the container:

crontab -l

@reboot python3.10 /opt/django/manage.py runserver 0.0.0.0:8002

But when I stop and start container with portainer the python didn't execute


Solution

  • The way you're trying to do this is not correct. Go to python image page on Docker hub, get the Dockerfile

    FROM python:3
    
    WORKDIR /usr/src/app
    
    COPY requirements.txt ./
    RUN pip install --no-cache-dir -r requirements.txt
    
    COPY . .
    
    CMD [ "python", "./your-daemon-or-script.py" ]
    

    Then build your image. The script will start on container startup.