Search code examples
pythondockercron

Python Script with Cronjob in Docker Container can't find Modules


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

Solution

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