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
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.
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.
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.
Make sure that you already installed cron
with your Dockerfile
It should be something like
RUN apt-get install -y cron
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With