[root@10-7-47-66 collect_data]# docker run -it rao/collect_data:v1 date
Mon Mar 9 02:39:31 UTC 2020
[root@10-7-47-66 collect_data]# date
Mon Mar 9 10:39:32 CST 2020
解决方案,将linux主机的时间映射到容器中
[root@10-7-47-66 collect_data]# docker run -it -v "/etc/localtime:/etc/localtime" rao/collect_data:v1 date
Mon Mar 9 10:42:23 CST 2020
可以解决以下报错
Traceback (most recent call last):
File "test.py", line 16, in <module>
scheduler = BackgroundScheduler(daemon=True)
File "/usr/local/lib/python3.6/site-packages/apscheduler/schedulers/base.py", line 87, in __init__
self.configure(gconfig, **options)
File "/usr/local/lib/python3.6/site-packages/apscheduler/schedulers/base.py", line 126, in configure
self._configure(config)
File "/usr/local/lib/python3.6/site-packages/apscheduler/schedulers/background.py", line 29, in _configure
super(BackgroundScheduler, self)._configure(config)
File "/usr/local/lib/python3.6/site-packages/apscheduler/schedulers/base.py", line 697, in _configure
self.timezone = astimezone(config.pop('timezone', None)) or get_localzone()
File "/usr/local/lib/python3.6/site-packages/tzlocal/unix.py", line 131, in get_localzone
_cache_tz = _get_localzone()
File "/usr/local/lib/python3.6/site-packages/tzlocal/unix.py", line 125, in _get_localzone
raise pytz.UnknownTimeZoneError('Can not find any timezone configuration')
pytz.exceptions.UnknownTimeZoneError: 'Can not find any timezone configuration'
docker 中 apscheduler 报错
Traceback (most recent call last):
File "test.py", line 17, in <module>
scheduler.add_job(sensor, 'interval', seconds=2)
File "/usr/local/lib/python3.6/site-packages/apscheduler/schedulers/base.py", line 420, in add_job
'trigger': self._create_trigger(trigger, trigger_args),
File "/usr/local/lib/python3.6/site-packages/apscheduler/schedulers/base.py", line 921, in _create_trigger
return self._create_plugin_instance('trigger', trigger, trigger_args)
File "/usr/local/lib/python3.6/site-packages/apscheduler/schedulers/base.py", line 906, in _create_plugin_instance
return plugin_cls(**constructor_kwargs)
File "/usr/local/lib/python3.6/site-packages/apscheduler/triggers/interval.py", line 38, in __init__
self.timezone = astimezone(timezone)
File "/usr/local/lib/python3.6/site-packages/apscheduler/util.py", line 87, in astimezone
'Unable to determine the name of the local timezone -- you must explicitly '
ValueError: Unable to determine the name of the local timezone -- you must explicitly specify the name of the local timezone. Please refrain from using timezones like EST to prevent problems with daylight saving time. Instead, use a locale based timezone name (such as Europe/Helsinki).