Tag - registrator

docker consul registrator    2017-07-19 21:01:41    8

参考文章:http://gliderlabs.com/registrator/latest/user/quickstart/

 

Consul是强一致性的数据存储,使用gossip形成动态集群。它提供分级键/值存储方式,不仅可以存储数据,而且可以用于注册器件事各种任务,从发送数据改变通知到运行健康检查和自定义命令,具体如何取决于它们的输出

Registrator通过检查容器在线或者停止运行状态自动注册和去注册服务,它目前支持etcd、Consul和SkyDNS 2

 

单机运行 consul服务


# docker run -d -p 8400:8400 -p 8500:8500 -p 8600:53/udp --name node4  gliderlabs/consul-server:0.6 -bootstrap -advertise 192.168.10.138

通过http API 查看consul服务

 

# curl 192.168.10.138:8500/v1/catalog/services 

{"consul":[]}

运行 Registrator

# docker run -d  --name=registrator  --net=host  --volume=/var/run/docker.sock:/tmp/docker.sock   gliderlabs/registrator:latest  consul://192.168.10.138:8500

 

Running Redis


# docker run -d -P --name=redis redis

测试Registrator配置是否有效


 
# curl 192.168.10.138:8500/v1/catalog/services 
 
{"consul":[],"redis":[]}


# curl 192.168.10.138:8500/v1/catalog/service/redis

[{"Node":"23dcba46458b","Address":"192.168.10.138","ServiceID":"localhost.localdomain:redis:6379","ServiceName":"redis","ServiceTags":[],"ServiceAddress":"","Servi
docker consul registrator consul-template HA    2017-07-19 20:54:24    8

compose文件:

version: '2'
services:
    consul-server:
        image: gliderlabs/consul-server:0.6
        command: -bootstrap -advertise 192.168.10.138
        hostname: consul-server
        ports:
            - "8400:8400"
            - "8500:8500"
            - "8600:53/udp"

    registrator:
        image: gliderlabs/registrator:latest
        command: consul://consul-server:8500
        hostname: registrator
        depends_on:
            - consul-server
        volumes:
            - /var/run/docker.sock:/tmp/docker.sock
    app:
      image: tutum/hello-world:latest
      environment:
        # Environment variables used by registrator to register services in consul
        SERVICE_NAME: app
        SERVICE_TAGS: sample
      ports:
        - "8081:80"
      depends_on:
        - consul-template-nginx
# Nginx Load Balancer
    consul-template-nginx:
      image: 1science/nginx:1.9.6-consul
      ports:
        - 80:80
      volumes:
        - ./etc/consul-template:/etc/consul-tem