Centos 7 Docker, Docker-compose, Registrator, Consul, Consul template and Nginx implement a highly extensible web framework

Source: Internet
Author: User

Install the required software

Docker

Docker-compose

The contents of the configuration Docker-compose.yml file are as follows:

#load balancer'll automatically update the config using consul-template

Lb:

Image:yeasy/nginx-consul-template:latest

Hostname:lb

Volumes

-/usr/soft/consul/logapi.conf:/etc/consul-templates/nginx.conf

Links

-Consulserver:consul

Ports

-"80:80"

Consulserver:

Image:gliderlabs/consul-server:latest

Hostname:consulserver

Ports

-"8,300:8,300"

-"8,301:8,301"

-"8301:8301/UDP"

-"192.168.190.131:8302:8302"

-"192.168.190.131:8302:8302/UDP"

-"192.168.190.131:8400:8400"

-"192.168.190.131:8500:8500"

-"53:53/UDP"

-"53:53"

Command:-data-dir/tmp/consul-bootstrap-advertise 192.168.190.131

Registrator:

Image:gliderlabs/registrator:latest

Hostname:registrator

Links

-Consulserver:consul

Volumes

-"/var/run/docker.sock:/tmp/docker.sock"

command:consul://consul:8500

LOGAPI:

Image:logapi-1-0-app

Environment:

Service_80_name:http

Service_name:logapi

Service_tags:backend

Ports

-"60000"

Nginx template file/usr/soft/consul/logapi.conf content is as follows: Logapi name is the same as service_name name under Logapi node in docker-compose.yml file

Upstream App {

{{Range service ' Logapi '}}server {.} address}}:{{. Port}} max_fails=3 fail_timeout=60 weight=1;

{{Else}}server 127.0.0.1:65535; # force a 502{{end}}

}

server {

Listen default_server;

Location/{

Proxy_pass Http://app;

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

Proxy_set_header Host $host;

Proxy_set_header X-real-ip $remote _addr;

}

}

Go to the directory where the Docker-compose.yml file is located

Running sudo docker-compose up

View Run status

Firewall on appropriate port

Port number for the Logapi-1-0-app container for 32860 ports

sudo firewall-cmd--zone=public--add-port=8500/tcp--permanent

sudo firewall-cmd--zone=public--add-port=32861-33000/tcp--permanent

sudo firewall-cmd--reload

View site content returned as follows:

Curl http://192.168.190.131

{"Status": 1, "message": "", "data": {"HostName": "Fdbd2c30b6c4", "IP": ["172.17.0.2", "172.17.0.2", "172.17.0.2"]}}

Open 2 Sites

sudo docker-compose scale logapi=2

Re-access Site content

 

Centos 7 Docker, Docker-compose, Registrator, Consul, Consul template, and Nginx implement a highly extensible web framework

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.