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 this Consul is running:
METHOD1:
In Docker-machine, run
$ docker PS
would see running Consul container:
We can also check the logs:
$ docker Logs $CONTAINER _id
METHOD2:
Browse to $DOCKER _ip:8500 There was a dashboard to see the services that was registered in Consul:
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 all Docker container by inspecting containers as they com E online.
Registrator Watches for new Docker containers and inspects them to determine what services they provide. For we purposes, a service is anything listening on a port. Any services Registrator finds on a container, they would 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 this registrator is running?
In Docker-machine, run
$ docker PS
would see running Registrator container:
We can also check the logs:
$ docker Logs $CONTAINER _id
3. Start a Web service and let Registrator automatically register it on Consul
In command line, into a directory of that have 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 the This service is registered?
METHOD1:
Use Consul API:
$ Curl $DOCKER _ip/v1/catalog/services
We can check the service details using Consul HTTP API:
$ Curl http://localhost:8500/v1/catalog/service/$SERVICE _name
METHOD2:
Check in Consul UI:
4. Find the IP address and port of the service from Consul UI, and start using the service.
Now we is ready for access the service from browser:
Consul & Registrator & Rails Service All together in separate Docker container