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

Source: Internet
Author: User
Tags docker ps

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.