作者:吴由兴_834 | 来源:互联网 | 2023-05-18 23:45
Iamtryingtomakesurethatmyappcontainerdoesnotrunmigrationsstartuntilthedbcontaine
I am trying to make sure that my app container does not run migrations / start until the db container is started and READY TO accept connections.
我试图确保我的应用程序容器在db容器启动和READY TO接受连接之前不运行迁移/启动。
So I decided to use the healthcheck and depends on option in docker compose file v2.
所以我决定使用healthcheck并依赖于docker compose file v2中的选项。
In the app, I have the following
在应用程序中,我有以下内容
app:
...
depends_on:
db:
condition: service_healthy
The db on the other hand has the following healthcheck
另一方面,db具有以下健康检查
db:
...
healthcheck:
test: TEST_GOES_HERE
timeout: 20s
retries: 10
I have tried a couple of approaches like :
我尝试了几种方法,如:
- making sure the db DIR is created
test: ["CMD", "test -f var/lib/mysql/db"]
- 确保db DIR已创建测试:[“CMD”,“test -f var / lib / mysql / db”]
- Getting the mysql version:
test: ["CMD", "echo 'SELECT version();'| mysql"]
- 获取mysql版本:test:[“CMD”,“echo'SELECT version();'| mysql”]
- Ping the admin (marks the db container as healthy but does not seem to be a valid test)
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
- Ping管理员(将数据库容器标记为健康,但似乎不是有效测试)测试:[“CMD”,“mysqladmin”,“ping”,“ - h”,“localhost”]
Does anyone have a solution to this?
有人有解决方案吗?
3 个解决方案