How can one Docker container call another Docker container

前端 未结 3 897
萌比男神i
萌比男神i 2021-02-05 21:08

I have two Docker containers

  1. A Web API
  2. A Console Application that calls Web API

Now, on my local web api is local host and Console applicat

3条回答
  •  礼貌的吻别
    2021-02-05 21:51

    The idea is not to pass the url, but the hostname of the other container you want to call.
    See 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.

    This is what replace the deprecated --link option.

    And if your containers are not running on a single Docker server node, Docker Swarm Mode would enable that discoverability across multiple nodes.

提交回复
热议问题