【问题标题】:How can I link a container spawned by one compose file to a container which is spawned by another compose file?如何将一个撰写文件生成的容器链接到另一个撰写文件生成的容器?
【发布时间】:2016-10-12 14:04:46
【问题描述】:

假设我们有两个撰写文件。编写文件“A”和“B”。
它们都是产卵容器。
composefile "A" 中的容器之一需要与 composefile "B" 链接。
如何?

我曾尝试使用 external_links,但没有运气。
任何建议,将不胜感激。

【问题讨论】:

  • 您可以使用标准的link 并链接撰写文件,请参阅docs.docker.com/compose/reference/overview/#/… Use the -f flag to specify the location of a Compose configuration file. You can supply multiple -f configuration files. When you supply multiple files, Compose combines them into a single configuration. Compose builds the configuration in the order you supply the files. Subsequent files override and add to their successors

标签: docker containers docker-compose


【解决方案1】:

使用 docker compose v2 语法,您可以通过在两个 docker compose 文件中指定相同的默认网络,将它们全部放在同一个 docker 网络上:

networks: default: external: name: myapp_net

它可能会给你一个警告,告诉你网络不存在,在这种情况下你只需运行它在警告中给出的命令。在此之后,来自两个撰写文件的容器应该能够相互访问。

在我的一个项目here中有一个例子。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    • 2011-04-24
    • 2020-12-12
    • 2018-05-30
    • 2020-12-02
    • 2014-01-02
    相关资源
    最近更新 更多