目標:經過Docker的方式部署MySql和zipkin,實現zipkin調用mysqlmysql
解決方案:讓須要連接的容器同屬一個外部網絡
第一步:定義容器mysql的docker-compose.yml文件,內容以下:sql
version: '2' services: db: image: hub.c.163.com/library/mysql:5.7 container_name: mysql volumes: - /Users/xiewanzhi/mysql_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: 123456 MYSQL_DATABASE: testDB ports: # Port used for the Zipkin UI and HTTP Api - 3306:3306 networks: - default - app_net networks: app_net: external: true
第二步:定義容器zipkin的docker-compose.yml文件,內容以下:docker
version: '2' services: # The zipkin process services the UI, and also exposes a POST endpoint that # instrumentation can send trace data to. Scribe is disabled by default. zipkin: image: openzipkin/zipkin:2.4.4 container_name: zipkin environment: - STORAGE_TYPE=mysql # Point the zipkin at the storage backend - MYSQL_DB=zipkin - MYSQL_USER=root - MYSQL_PASS=123456 - MYSQL_HOST=mysql - MYSQL_TCP_PORT=3306 # Uncomment to enable scribe # - SCRIBE_ENABLED=true # Uncomment to enable self-tracing # - SELF_TRACING_ENABLED=true # Uncomment to enable debug logging # - JAVA_OPTS=-Dlogging.level.zipkin=DEBUG -Dlogging.level.zipkin2=DEBUG ports: # Port used for the Zipkin UI and HTTP Api - 9411:9411 # Uncomment if you set SCRIBE_ENABLED=true # - 9410:9410 networks: - default - app_net networks: app_net: external: true
這裏兩個容器的定義裏都使用了同一個外部網絡 app_net ,所以,咱們須要在啓動這兩個容器以前經過如下命令再建立外部網絡:bash
docker network create app_net
以後,經過 docker-compose up -d 命令啓動這兩個容器,而後執行 docker exec -it zipkin ping mysql,你將會看到以下的輸出:網絡
MacBook-Pro:docker-zipkin mymac$ docker exec -it zipkin ping mysql PING mysql (172.20.0.2): 56 data bytes 64 bytes from 172.20.0.2: seq=0 ttl=64 time=0.100 ms 64 bytes from 172.20.0.2: seq=1 ttl=64 time=0.149 ms 64 bytes from 172.20.0.2: seq=2 ttl=64 time=0.145 ms 64 bytes from 172.20.0.2: seq=3 ttl=64 time=0.143 ms 64 bytes from 172.20.0.2: seq=4 ttl=64 time=0.652 ms 64 bytes from 172.20.0.2: seq=5 ttl=64 time=0.128 ms 64 bytes from 172.20.0.2: seq=6 ttl=64 time=0.210 ms
證實這兩個容器是成功連接了。app
此時http://127.0.0.1:9411/zipkin/能夠提供追蹤服務了debug