OStack程序员社区-中国程序员成长平台

标题: docker - 一个 Docker 容器如何调用另一个 Docker 容器 [打印本页]

作者: 菜鸟教程小白    时间: 2022-8-3 10:10
标题: docker - 一个 Docker 容器如何调用另一个 Docker 容器

我有两个 Docker 容器

  • 一个Web API
  • 一个调用 Web API 的控制台应用程序

  • 现在,在我的本地 web api 上是本地主机,并且控制台应用程序调用 API 没有问题。但是,我不知道这两个东西什么时候被 Dockerized,我怎么可能让 Dockerized API 的 Url 可用于 Dockerized Console 应用程序?

    我认为我不需要 Docker Compose,因为我将 API 的 Url 作为 API 的参数传递,因此只需确保 Dockerized API's url 可以通过 Dockerized Console 访问

    有任何想法吗?



    Best Answer-推荐答案


    这个想法不是传递 url,而是你想要调用的另一个容器的主机名。
    Networking in Compose

    By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.



    这就是取代 deprecated --link option 的原因.

    如果您的容器不在单个 Docker 服务器节点上运行,Docker Swarm Mode将启用跨多个节点的可发现性。

    关于docker - 一个 Docker 容器如何调用另一个 Docker 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44275794/






    欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4