跨主机访问 Memcached 容器

Memcached container access across hosts

我有两台主机 HostA 和 HostB,它们目前使用安装在 HostA 上的 memcached。我正在 HostA 上容器化 memcached,使用来自 HostA 的这个容器的服务可以通过使用主机名作为 'memcached' 和端口“11211”来连接到它。当我从 HostB 连接到这个容器时,我应该使用什么主机名?我应该使用 HostA 的 IP 地址和端口 11211 吗?

一种选择是使用 HostA 的 IP 地址和端口 11211,正如您提到的,只要 port is exposed and firewall rules set appropriately.

另一种选择是创建一个 overlay network and keep using the name of the container (e.g. memcached). It's a bit more difficult to set up and requires an extra piece of software for service discovery (e.g. Consul, ZK, etcd). On the bright side, it also makes the whole thing more dynamic. A good reference in this blog post