Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker crontab: not found

I use django-crontab in my project. Locally in my project work fine. But I want to use Docker. When I run Docker, I have the following error:

/bin/sh: 1: /usr/bin/crontab: not found

My docker-compose.yml

version: '2.0'
services:
  web:
    build: .
    container_name: test_api
    volumes:
      - .:/usr/django/app/
    expose:
      - "8000"
    env_file: main.env
    command: bash django_run.sh

  nginx:
    build: ./nginx
    container_name: test_ng
    ports:
      - "8000:8000"
    volumes:
      - ./nginx/api.conf:/etc/nginx/conf.d/api.conf
      - .:/usr/django/app/
    depends_on:
      - web
    links:
      - web:web

django_run.sh

#!/usr/bin/env bash
set -e

if [ "$ADD_CRON" == "true" ]; then
    python manage.py crontab show
fi

if [ "$ADD_CRON" == "true" ]; then
    python manage.py crontab add
fi

if [ "$ADD_CRON" == "true" ]; then
    python manage.py crontab show
fi

if [ "$ADD_CRON" == "true" ]; then
    python m/usr/local/bin/gunicorn ${DJANGO_APP}.wsgi:application --timeout ${GUNICORN_TIMEOUT} --keep-alive ${GUNICORN_KKEP_ALIVE} -k gevent -w ${GUNICORN_WORKERS} --threads ${GUNICORN_THREADS} -b :${GUNICORN_PORT}

My logs:

test_api | /bin/sh: 1: /usr/bin/crontab: not found
test_api | Currently active jobs in crontab:
test_api | /bin/sh: 1: /usr/bin/crontab: not found
test_api | sh: 1: /usr/bin/crontab: not found
test_api |   adding cronjob: (649feb1a8431f09891b644aa4ba2075b) -> ('*/1 * * * *', 'cron.cron_jubs.clear_pdf_files_scheduled_job', '>> /tmp/scheduled_job.log')
test_api | /bin/sh: 1: /usr/bin/crontab: not found
test_api | Currently active jobs in crontab:
test_api | [2018-03-15 14:23:41 +0000] [35] [INFO] Starting gunicorn 19.7.1
like image 712
nesalexy Avatar asked Mar 15 '18 14:03

nesalexy


People also ask

Why crontab is not working?

Why is crontab not working in your system? Crontab might fail for a variety of reasons: The first reason is that your cron daemon might not be working for any reason, resulting in your crontab failing. There also exists a possibility that your system's environment variables are not settled correctly.

How do I know if crontab is running?

To check to see if the cron daemon is running, search the running processes with the ps command. The cron daemon's command will show up in the output as crond. The entry in this output for grep crond can be ignored but the other entry for crond can be seen running as root. This shows that the cron daemon is running.

Why use Docker?

Fast, consistent delivery of your applications Docker streamlines the development lifecycle by allowing developers to work in standardized environments using local containers which provide your applications and services. Containers are great for continuous integration and continuous delivery (CI/CD) workflows.


1 Answers

Make sure that you already installed cron with your Dockerfile

It should be something like

RUN apt-get install -y cron
like image 109
Dcoder Avatar answered Oct 17 '22 06:10

Dcoder