skip to Main Content

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

Answers


  1. Chosen as BEST ANSWER

    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
    

  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search