Consul & Registrator & Rails Service all together in separate Docker container

1.Start a container running Consul:

Here we use this image: https://hub.docker.com/r/progrium/consul/

$ docker run -it -h node -p 8500:8500 -p 53:53/udp progrium/consul -server -bootstrap -advertise  $DOCKER_IP


How to check that Consul is running:

Method1:

In Docker-Machine, run

$ docker ps

Will see running Consul container:

3

We can also check the logs:

$ docker logs $CONTAINER_ID

3

Method2:

Browse to $DOCKER_IP:8500 there is a dashboard to see the services that are registered in Consul:

3



2.Start a container running Registrator

Here we use this image: https://hub.docker.com/r/gliderlabs/registrator/

Registrator automatically registers and deregisters services for any Docker container by inspecting containers as they come online.

Registrator watches for new Docker containers and inspects them to determine what services they provide. For our purposes, a service is anything listening on a port. Any services Registrator finds on a container, they will be added to a service registry, such as Consul or etcd.

$ docker run -it -v /var/run/docker.sock:/tmp/docker.sock -h $DOCKER_IP gliderlabs/registrator consul://$DOCKER_IP:8500


How to check that Registrator is running?

In Docker-Machine, run

$ docker ps

Will see running Registrator container:

3

We can also check the logs:

$ docker logs $CONTAINER_ID

3



3. Start a web service and let Registrator automatically register it on Consul

In command line, into a directory that has proper rails app, Dockerfile and docker-compose.yml file in place.

$ docker-compose build
$ docker-compose run web bundle exec rake sample_data:populate
$ docker-compose run -p 3000 -e 'SERVICE_NAME=romui-web' web rails s

How to check that this service is registered?

Method1:

Use Consul API:

$ curl $DOCKER_IP/v1/catalog/services

3

We can check the service details using Consul HTTP API:

$ curl http://localhost:8500/v1/catalog/service/$SERVICE_NAME

3

Method2:

Check in Consul UI:

3


4. Find the IP address and port of the service from Consul UI, and start using the service.

3

Now we are ready to access the service from browser:

2


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值