# HAProxy Container Setup

**URL:** <https://discourse.haproxy.org/t/haproxy-container-setup/1833>\
**Category:** Help!\
**Created:** [November 27, 2017, 12:29am UTC](https://discourse.haproxy.org/t/haproxy-container-setup/1833 "2017-11-27T00:29:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BananaLolzerz](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@BananaLolzerz](https://discourse.haproxy.org/u/BananaLolzerz)\
**Post date:** [November 27, 2017, 12:29am UTC](https://discourse.haproxy.org/t/haproxy-container-setup/1833/1 "2017-11-27T00:29:09Z")

</div>

So I have read the documentation but honestly without seeing an actual example of a config I am really having a hard time getting my head wrapped around this.

I have the following setup:

![](https://us1.discourse-cdn.com/flex016/uploads/haproxy/original/1X/46025e704e93e5895b2b115adcf249ac12666c72.png)

I have 1x physical baremetal machine that has Ubuntu running with HAProxy installed as an application directly on the operating system and then Docker that is running multiple containers.

![](https://us1.discourse-cdn.com/flex016/uploads/haproxy/original/1X/33be7cfbce3299d56b50c560ef44be1ce9ac0d4a.png)

![](https://us1.discourse-cdn.com/flex016/uploads/haproxy/original/1X/1a8f5c096cf694f49691a7ede4ef61439dbc66aa.png)

 ![](https://us1.discourse-cdn.com/flex016/uploads/haproxy/original/1X/b174776b71c87816b2e16ebefbf46e3f397eaae5.png)

Before anyone freaks out, this is just running as a temporary/example and is NOT production.

But I am not sure how to write out the HAProxy config file. I have it currently as:

[https://hastebin.com/edibifetif.cfg](https://hastebin.com/edibifetif.cfg)

I have the following domains that are going to be pointing to my public IP:

- [chat.temp.com](http://chat.temp.com)
- [cloud1.temp.com](http://cloud1.temp.com)
- [crm.temp.com](http://crm.temp.com)

Can someone please assist me with showing the config file should be written. I am looking at this tutorial:

> **[How to install HAProxy load balancer on Ubuntu - UpCloud](https://upcloud.com/community/tutorials/haproxy-load-balancer-ubuntu/)**
>
> This guide lays out the steps for setting up HAProxy as a load balancer on Ubuntu 16 to its own cloud host which then directs the traffic to your web servers.

But I am not sure if the containers would be properly like this:

[https://hastebin.com/danuparoqi.cfg](https://hastebin.com/danuparoqi.cfg)

Can someone please help out?

---

<div class="post-metadata">

**Author:** ![hans0r](https://avatars.discourse-cdn.com/v4/letter/h/f05b48/32.png) [@hans0r](https://discourse.haproxy.org/u/hans0r)\
**Post date:** [November 27, 2017, 8:18am UTC](https://discourse.haproxy.org/t/haproxy-container-setup/1833/2 "2017-11-27T08:18:02Z")

</div>

Hi,

as I can see your global/default configuration is default. Thats a config to start with… but your config has some mistakes.

It looks like you try to load-balance between to different application services! I think you must separate this. I attached a simple example for you. In the example there where 2 frontends (one for your services ans one for the stats) and multiple backends for your services eg. chat cloud etc.

```
   frontend http_FE
   bind *:80
  
   acl is_chat hdr(host) -i chat.temp.com
   acl is_cloud hdr(host) -i cloud1.temp.com -i cloud2.temp.com
   
   use_backend chat_BE if is_chat
   use_backend cloud_BE if is_cloud
   
   #default_backend http_back
   # you can use the default backend, but in my example I don't use it

backend chat_BE
   mode http # I prefer to specify the backend mode per backend, I think it better for the abstract
   #balance roundrobin you don't need this because you only have one backend for the chat
   server chat.temp.com 172.17.0.4:4002 check
   
backend cloud_BE
   mode http # I prefer to specify the backend mode per backend, I think it better for the abstract
   #balance roundrobin you don't need this because you only have one backend for the chat
   server cloud1.temp.com 172.17.0.2:4001 check
   
listen stats
   bind *:9999
   mode http
   stats enable
   stats realm Haproxy\ Stats
   stats uri /haproxy_stats
   stats auth user:pw
   stats admin if TRUE # with this option it is possible to switch your backend-server in maintain-mode etc.

```

I hope that is mistake free… it’s fast written in Notepad++

All is my personal preference… You can do things different!

Greets hans0r
