0

I have a very big problem I'm struggling with for 3 days.

I use docker swarm on the remote server. 20 microservices are in the same network NetA and stack StackA.

Now I want to add Zipkin and Sleuth to my microservices to trace all requests.

All microservices are made by docker-compose file that looks like:

version: '3'

services:
  myservice1:
    image: myImage1
    depends_on:
      - myService2
      - myService3
    ports:
      - "8081:80"
    environment:
      - TZ=Europe/Warsaw


  myservice3:
    image: myImage2
    environment:
      - profile=${MY_PROFILE}
      - TZ=Europe/Warsaw

...

Now the question is - HOW to ADD Zipkin Server?

I've added Zipkin server from Docker Hub Image.

NOW my ZIpkin Service is: - in a separate network ZIPN - in a separate stack ZIPST

What should I do to send data do Zipkin by all my microservices? What URL should i send in properties file: spring.zipkin.base-url=http://zipkinserver_network_zipkin_server:9411/

Should it be maybe: -container name (like my_zipkin_server) - but I use swarm so container name changes dynamically? - network name?

I added an additional network NetA to my Zipkin container but it didn't solved my problem - there are no traces in my Zipkin UI.

Please help me, I spent 4 days with this problem without any success.

Zipkin server should be in a separate Stack because will be used by different applications.

There is only ONE case when Zipkin works: when I set Zipkin container name:

spring.zipkin.base-url=http://zipkinserver_container_name:9411/
Matley
  • 1,953
  • 4
  • 35
  • 73

2 Answers2

2

First specify your own overlay network (see bottom of code below) and use it for your services.

version: '3'

services:
  myservice1:
    image: myImage1
    depends_on:
      - myService2
      - myService3
    ports:
      - "8081:80"
    environment:
      - TZ=Europe/Warsaw
    networks:
      - backbone

  myservice3:
    image: myImage2
    environment:
      - profile=${MY_PROFILE}
      - TZ=Europe/Warsaw
    networks:
      - backbone

networks:
  backbone:
   driver: overlay

Then in your compose file for your other services like ZIpkin, add the backbone network to its list. Eg:

version: '3'

services:
  ZIpkin:
    image: myZImage
    networks:
      - ZIPN
      - backbone

networks:
  backbone:
   external:
     name:  PROJ_backbone

Note that outside of the first compose file, you'll need to prefix the project name for your network. Unless you set the environment variable COMPOSE_PROJECT_NAME it will be the name of the directory that the compose file is in. Do a docker network ls to find out the full name of the network to use.

Bernard
  • 16,149
  • 12
  • 63
  • 66
  • Thank you Alkaline for your answer. But I don't understand your last sentences: " you'll need to prefix the project name for your network. " And what the URL to the ZIpkin should look like? – Matley Feb 02 '19 at 13:34
  • 1
    @Matley Just do a `docker network ls` and look at what your network names look like. You'll see that they look like `XXXX_MyNetworkName`. When you reference a volume or network defined in another compose file, you need to add the XXXX_ prefix, or create a alas like I show above (external: name) – Bernard Feb 03 '19 at 23:59
0

OK, so I solved my problem using only docker-compose files. By Portainer I pasted my second docker-compose file in Stack section (I creaated new Stack):

version: '3'
services:

  my_name_zipkin: --> THIS NAME SHOULD WE USE WHEN WE'D LIKE TO COMMUNICATE WITH CONTAINER
    image: openzipkin/zipkin
    ports:
      - "9411:9411"
    networks:
      - zipkin
      - my_old_network_with_services
networks:
  zipkin:
  my_old_network_with_services:
    external: true

Now we should use 'my_name_zipkin' name to communicate with this service. Service name is the name we should use to communicate between containers.

So in properties file I set:

spring.zipkin.base-url=http://zipkin:9411/
Matley
  • 1,953
  • 4
  • 35
  • 73