1

If I run a pythonscript in my container, it runs whithout any problms. But when I run it as a cronjob, it throws an error, that it found no module. Do you have any ideas why?

dockerfile

FROM python:3.5.2

RUN apt-get update \
    && apt-get install -y cron \
    && apt-get autoremove -y

RUN pip install --upgrade pip && \
    pip install --no-cache-dir image pytesseract numpy XlsxWriter pandas requests && \
    pip install --no-cache-dir med2image datetime IPython matplotlib

# Create a volume
VOLUME /logSent

# Copy Scriptfile
COPY script.py ./script.py

# Copy cron file to the cron.d directory
COPY cronpy /etc/cron.d/cronpy
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/cronpy
# Apply cron job
RUN crontab /etc/cron.d/cronpy

CMD ["cron", "-f"]

cronpy

*/10 * * * * python /script.py > /proc/1/fd/1 2>/proc/1/fd/2
# Empty line
Bsel
  • 85
  • 9
  • Relevant [How to simulate the environment cron executes a script with?](https://stackoverflow.com/questions/2135478/how-to-simulate-the-environment-cron-executes-a-script-with) – stovfl Apr 17 '20 at 14:55

2 Answers2

1

okay when I use an ubuntu-image and install python by myself and not the python-image it runs correctly.

Bsel
  • 85
  • 9
-1

Try using an absolute path for python in cronpy, e.g.

*/10 * * * * /usr/bin/python /script.py > /proc/1/fd/1 2>/proc/1/fd/2
nikolaiwo
  • 1
  • 2
  • 1
    Thanks but there is still the exception "ImportError: No module named ..." – Bsel Apr 17 '20 at 14:11
  • 2
    @Bsel Did you make sure to use the same python executable as you did when running the executable manually? I see that the default python in the `python:3.5.2` image is `/usr/local/bin/python` – nikolaiwo Apr 20 '20 at 07:22