I am using Windows 10 and Docker Desktop. I pull Consul Docker images from Docker repository and try to containerize Consul Docker server to discover MySQL services. To add MySQL service into Consul Docker, I type in CONSUL environment variables.
For example:
CONSUL_SERVICE_ID=mysql
CONSUL_SERVICE_NAME=mysql8
CONSUL_SERVICE_ADDRESS=xxx.xxx.xxx.xxx
CONSUL_SERVICE_PORT=3306
But Consul Docker server can not discover the MySQL service when running the Consul container. The Docker images I pull are consul
and gliderlabs/consul-server
.
How can I register MySQL service into Consul Docker server? When installing Consul server on localhost, not containerizing, Consul server discover the MySQL service successfully. I have no idea how on Docker.
You can define an externally running container in a docker-compose file that is not actually defined in the same file using 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