我使用 django-crontab在我的项目中。在我的项目中本地工作正常。但我想使用 Docker。当我运行 Docker 时,出现以下错误:
/bin/sh: 1: /usr/bin/crontab: not found
我的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}
我的日志:
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
最佳答案
确保您已经使用 Dockerfile 安装了 cron
应该是这样的
RUN apt-get install -y cron
关于python - docker crontab : not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49302298/