'haproxy docker'에 해당되는 글 1건

  1. 2017.03.24 HAProxy with Docker

HAProxy with Docker

Docker 2017. 3. 24. 22:14

Use HAProxy with Docker


1. Create Dockerfile for HAProxy Build with Docker 

1
2
FROM haproxy:1.7 // Set HAProxy version
ADD haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
cs


2. Docker build using Dockerfile created

1
docker build -t my-haproxy .
cs


3.  After you build Dockerfile, you can find docker images that is my-haproxy 

1
2
3
$ docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
my-haproxy                              latest              98f53e224010        5 hours ago         134.9 MB
cs


4. To create HAProxy you should make haproxy.cfg that is configure file for haproxy. 

For test I already created two nodes

haproxy.cfg are contained health check 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
global
 
  log 127.0.0.1  local0
  log 127.0.0.1  local1 notice
  maxconn  8192
 
defaults
  balance roundrobin
  log     global
  mode    tcp
  option  tcplog
  option  redispatch
  option  log-health-checks
  retries 5
  maxconn 8192
  timeout connect 50s
  timeout client  500s
  timeout server  500s
 
listen stats
  bind  *:1936
  mode  http
  stats enable
  stats uri /stats
  stats auth guest:guest
  stats refresh 5s
 
listen web
bind *:80 mode http balance roundrobin server web1 172.17.0.8:7777 check server web2 172.17.0.9:7778 check
cs


  • stats
    • Set haproxy monitoring
    • You can connect [host_ip]:1936/stats and see haproxy web ui
    • auth - account ID / account PW
  • web
    • Bind 80 port.
    • balance mode is roundrobin.
    • health check for web1, web2.

5. Use haproxy.cfg that you set to run the docker.
1
docker run -d -p 1936:1936 -p 80:80 --name docker-haproxy my-haproxy
cs

6. If docker is run well, You can see the stats UI.
Through [host_ip]:1936/stats, You can see web ui below.




Posted by 사용자 guru_k

댓글을 달아 주세요