如何将 mysql 服务添加到 Consul docker 容器中?

How to add mysql services into Consul docker container?

我正在使用 windows 10 和 docker 桌面。 我从 docker 存储库中提取 consul docker 图像,并尝试将 consul docker 服务器容器化以发现 mysql 服务。要将 mysql 服务添加到 consul docker,我输入了 CONSUL 环境变量。例如,

CONSUL_SERVICE_ID=mysql
CONSUL_SERVICE_NAME=mysql8
CONSUL_SERVICE_ADDRESS=xxx.xxx.xxx.xxx
CONSUL_SERVICE_PORT=3306

但是当 运行 consul 容器时,consul docker 服务器无法发现 mysql 服务。我提取的 docker 图像是 consulgliderlabs/consul-server 如何将 mysql 服务注册到 consul docker 服务器中?在本地主机上安装 consul 服务器时,未容器化时,consul 服务器成功发现 mysql 服务。我不知道 docker 怎么样。任何回复,请。

您可以在 docker-compose 文件中定义一个外部 运行 容器,但实际上并未使用 external_links.

在同一文件中定义该容器

external_links

Link to containers started outside this docker-compose.yml or even outside of Compose, especially for containers that provide shared or common services. external_links follow semantics similar to the legacy option links when specifying both the container name and the link alias (CONTAINER:ALIAS).

external_links:
 - redis_1
 - project_db_1:mysql
 - project_db_1:postgresql

Source