-1

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

marcosam
  • 27
  • 9
  • Normally the cron daemon doesn't run in a container. Try finding a tutorial on how to dockerize a Django app to get an idea of how to do it – Hans Kilian Feb 25 '23 at 16:19

2 Answers2

1

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.

Jarek
  • 782
  • 5
  • 16
0

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
marcosam
  • 27
  • 9