Dockerimages starting order
Yet another Docker issue. During an initial start, the workers
image starts BEFORE the mysql
image and fails to connect to the database (DB initialization takes some time). It results in:
workers_1 | Traceback (most recent call last):
workers_1 | File "/usr/share/vidjil/server/web2py/gluon/restricted.py", line 219, in restricted
workers_1 | exec(ccode, environment)
workers_1 | File "applications/vidjil/models/db.py", line 44, in <module>
workers_1 | db = DAL(defs.DB_ADDRESS,pool_size=defs.DB_POOL_SIZE,check_reserved=['all'])
workers_1 | File "/usr/share/vidjil/server/web2py/gluon/packages/dal/pydal/base.py", line 170, in __call__
workers_1 | obj = super(MetaDAL, cls).__call__(*args, **kwargs)
workers_1 | File "/usr/share/vidjil/server/web2py/gluon/packages/dal/pydal/base.py", line 475, in __init__
workers_1 | "Failure to connect, tried %d times:\n%s" % (attempts, tb)
Probably, this race condition could affect a usual run rather than only initial run.
The possible solution is using a special waiting script wait-for-it
(https://github.com/vishnubob/wait-for-it) like it shown here:
https://docs.docker.com/compose/startup-order/