gpt4 book ai didi

docker-compose up 容器开始排序

转载 作者:行者123 更新时间:2023-12-04 20:36:24 26 4
gpt4 key购买 nike

现在,link s 在 docker-compose.yml 中被弃用(并且我们能够使用新的网络功能在容器之间进行通信),我们已经失去了一种明确定义容器之间依赖关系的方法。现在,我们如何在 api-server 容器启动(通过 myapp_mysql_1 中的 dns 条目 docker-compose.yml 连接到 mysql)之前告诉我们的 mysql 容器先启动?

最佳答案

有可能使用“volumes_from”作为解决方法,直到引入了depends_on 功能(在下面讨论)。假设您有一个依赖于 php 容器的 nginx 容器,您可以执行以下操作:

nginx:
image: nginx
ports:
- "42080:80"
volumes:
- ./config/docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
volumes_from:
- php

php:
build: config/docker/php
ports:
- "42022:22"
volumes:
- .:/var/www/html
env_file: config/docker/php/.env.development

mongo:
image: mongo
ports:
- "42017:27017"
volumes:
- /var/mongodata/wa-api:/data/db
command: --smallfiles

上述方法中的一大警告是 php 的卷暴露给 nginx,这是不希望的。但目前这是可以使用的一种特定于 docker 的解决方法。

依赖功能 这可能是一个 future 主义的答案。因为该功能尚未在 Docker 中实现(从 1.9 开始)

There is a proposal to introduce "depends_on" in the new networking feature introduced by Docker. But there is a long running debate about the same @ https://github.com/docker/compose/issues/374 Hence, once it is implemented, the feature depends_on could be used to order the container start-up, but at the moment, you would have to resort to the above approach.

关于docker-compose up 容器开始排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34647345/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com