docker - 如何连接在两个不同主机中运行的两个容器?

标签 docker

我在服务器A中运行一个Web容器,在服务器B中运行一个数据库容器。

如何连接这两个容器?

我只知道如何连接在同一主机中运行的两个容器。

最佳答案

你需要一个:

  • service discovery将记录您的容器主机(例如Consul,KV-键/值存储)

  • http://progrium.com/images/content/embassy/consul_layers.png

    A good way to think of Consul is broken into 3 layers.
    The middle layer is the actual config store, which is not that different from etcd or Zookeeper.
    The layers above and below are pretty unique to Consul.

    The killer feature of Consul is its service catalog. Instead of using the key-value store to arbitrarily model your service directory as you would with etcd or Zookeeper, Consul exposes a specific API for managing services.


  • 一个注册者(即使有点过大,您也可以使用swarm,或者 registrator )

  • Registrator is a single, host-level service you run as a Docker container.
    It watches for new containers, inspects them for service information, and registers them with a service registry. It also deregisters them when the container dies.
    It has a pluggable registry system, meaning it can work with a number of service discovery systems.

    关于docker - 如何连接在两个不同主机中运行的两个容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33757038/

    相关文章:

    amazon-web-services - 如何从dockerized spring boot上收集AWS上的日志?

    docker - Uncaught exception Failure ("input_value: bad bigarray kind") - Windows 和 Mgt 开发环境上的 Unison

    Docker入口点脚本根权限

    docker - IBM-Bluemix:IBM Containers报告的图像已压缩-比本地Docker引擎小

    amazon-web-services - 如何确定我的容器是否在 AWS ECS 上运行?

    amazon-web-services - 将Docker容器放入AWS EC2实例的动机

    .net - 无法为Dotnet核心Web应用程序从Docker文件构建Docker镜像

    ubuntu - 在 Ubuntu 中创建一个可以 sudo 的用户(Dockerfile)

    python-3.x - 无法使用SQLAlchemy连接到MYSQL

    linux - 我无法在 Docker 容器中获取环境变量