The configuration file of consul docker container which is monitoring the mysql server

I try to deploy spring boot application with mysql and monitor this simple architecture using consul docker container on windows 10. First I add bootstrap.yml file onto spring boot resources folder.

== bootstrap.yml

spring:
  profiles: default
  cloud:
    consul:
      host: 192.168.200.51
      port: 8500
      discovery:
        enabled: false
        prefer-ip-address: true
        healthCheckInterval: 300s
      config:
        enabled: true
        profileSeparator: '::'
        format: yaml
        fail-fast: false
  application:
    name: blog-service

And the next I add the @EnableDiscoveryClient annotation on the spring boot appplication like below,

@SpringBootApplication
@EnableDiscoveryClient 
public class SpringBlogJpaApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBlogJpaApplication.class, args);
    }

}

When this spring boot application is executed, consul server docker container recognize the blog-service successfully. However the consul server can not discover mysql service. Mysql Server is another docker container. So I add the config.json file into consul server docker container with docker exec console.

> cd config
> echo "{ \"services\": [ { \"id\": \"mysql\", \"name\": \"mysql 8\", \"tags\": [\"mysql\"], \"address\": \"0.0.0.0\", \"port\": 3306 } ] }" > config.json

But the mysql recognition is failed on Consul. I have no idea how to find the id and name of mysql process outside docker container. And more I have no idea whether this process is correct or not. The 3 docker containers are executed successfully on windows 10.

> docker ps -a

CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS              PORTS                                                                                NAMES
564f0c683d7e        gliderlabs/consul-server:latest   "/bin/consul agent -…"   About an hour ago   Up About an hour    8300-8302/tcp, 8400/tcp, 8301-8302/udp, 8600/tcp, 8600/udp, 0.0.0.0:8500->8500/tcp   Blog-Consul-Server
6284dd527545        application:latest                "java -Dfile.encodin…"   About an hour ago   Up About an hour    0.0.0.0:8080->8080/tcp                                                               Blog-App
1347587f7a62        mysql:latest                      "docker-entrypoint.s…"   About an hour ago   Up About an hour    0.0.0.0:3306->3306/tcp, 0.0.0.0:33060->33060/tcp                                     Blog-MySQL

How can the mysql procedure in docker container be discovered on consul server docker? If I am using wrong process, kindly inform me the right procedure.

Just to be curious… is there a reason you use consul for service discovery? Isn’t this a relic from the old docker swarm days, before docker did buildin the swarm mode into the docker engine? From what I remember you had to use Registrator to leverage container events to register containers in consul. It should help to register your mysql8 container with the required details.

Though with swarm mode, what is wrong with creating an external docker network, attach all your containers to it and use its build in dns name resolution for container to container communication?