[英]docker-compose up stucks on attaching to when running an python scheduler script
I have a simple python application to run some scheduled jobs. 我有一个简单的python应用程序来运行一些计划的作业。 I want these jobs to run non-stop as an script. 我希望这些作业作为脚本连续运行。
import os
import time
import requests
from apscheduler.schedulers.blocking import BlockingScheduler
from pytz import utc
def a_get_request_to_api():
request.get("some_url")
def another_get_request_to_api():
try:
request.get("some_url")
except Exception as e:
print(e)
if __name__ == "__main__":
print('STARTING SCHEDULER ...')
# initialize Blocking Scheduler
scheduler = BlockingScheduler(timezone=utc)
# add jobs to run on scheduled time
scheduler.add_job(a_get_request_to_api, trigger='interval', hours=1, max_instances=2)
scheduler.add_job(another_get_request_to_api, trigger='interval', hours=6, max_instances=2)
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
try:
scheduler.start()
except (KeyboardInterrupt, SystemExit) as e:
print(e)
this is fine and works when i run directly from terminal. 当我直接从终端运行时,这很好并且可以工作。
my Dockerfile
: 我的Dockerfile
:
FROM python:3.6-alpine
WORKDIR /app
RUN pip install requests apscheduler pytz
CMD [ "python", "scheduler.py" ]
and a simple docker-compose.yml
: 和一个简单docker-compose.yml
:
version: '3'
services:
scheduler:
build: .
volumes:
- .:/app
But when i dockerize the app and docker-compose up
it stucks at attaching to
但是当我对应用程序进行dockerize和docker docker-compose up
它卡在attaching to
I think you should try running docker-compose in detach mode : 我认为您应该尝试以分离模式运行docker-compose:
docker-compose up -d
-d, --detach Detached mode: Run containers in the background,
print new container names. Incompatible with
--abort-on-container-exit.
See https://docs.docker.com/compose/reference/up/ 参见https://docs.docker.com/compose/reference/up/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.