0

I'm trying to run a cronjob inside a docker container, and the logs (created with python logging) from docker logs my_container or from /var/log/cron.log. Neither is working. I tried a bunch of solutions I found in stackoverflow.

This is my Dockerfile:

FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04

ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Minsk
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update && apt-get install -y \
        python3-dev \
        python3-tk \
        python3-pip \
        libglib2.0-0\
        libsm6 \
        postgresql-server-dev-all \
        postgresql-common \
        openssh-client \
        libxext6 \
        nano \
        pkg-config \
        rsync \
        cron \
        && \
    apt-get clean && \
    apt-get autoremove && \
    rm -rf /var/lib/apt/lists/*
RUN pip3 install  --upgrade  setuptools
RUN pip3 install numpy
ADD requirements.txt /requirements.txt
RUN pip3 install -r /requirements.txt && rm /requirements.txt

RUN touch /var/log/cron.log
COPY crontab /etc/cron.d/cjob
RUN chmod 0644 /etc/cron.d/cjob

ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ENV PYTHONUNBUFFERED 1

ADD . /code
WORKDIR /code
COPY ssh_config /etc/ssh/ssh_config

CMD cron -f

and this is how I run it:

nvidia-docker run -d \
    -e DISPLAY=unix$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v /media/storage:/opt/images/ \
    -v /home/user/.aws/:/root/.aws/ \
    --net host \
    my_container

I tried different things such as:

But I don't get any logs.

pceccon
  • 9,379
  • 26
  • 82
  • 158

1 Answers1

0

Change your chmod code to 755 if you're trying to execute something from there. You might also want to add an -R parameter while at that.

Next, add the following to your Dockerfile before chmod layer.

# Symlink the cron to stdout
RUN ln -sf /dev/stdout /var/log/cron.log

And add this as your final layer

# Run the command on container startup
CMD cron && tail -F /var/log/cron.log 2>&1

Referenced this from the first link that you mentioned. This should work.

Abhinav Thakur
  • 383
  • 2
  • 7