python don´t excecute when start container with crontab

53 Views Asked by At

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

2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

Thanks I could resolve the problem I used the command:

docker run -it --name djangoapp -w /opt/django/ -p 8002:8002 <imagen>:1.0 python3.10 manage.py runserver 0.0.0.0:8002