Coder Social home page Coder Social logo

Comments (5)

tifayuki avatar tifayuki commented on July 26, 2024

@Bekt
You don't have to expose any ports on your application containers. Instead, you need to expose and publish the ports on haproxy container.

from dockercloud-haproxy.

Bekt avatar Bekt commented on July 26, 2024

Hi @tifayuki, yeah that is what I am asking. The expose property here is:

Expose ports without publishing them to the host machine - they’ll only be accessible to linked services. Only the internal port can be specified.

Anyway, the container internally exposes (not to the host) the two ports above. How can I tell haproxy to bind them to ports? More specific example:

app1:
  image: app1
  expose:
    - '4000' # I want haproxy to proxy port 4444 to this container port (4000)
    - '5000' # I want haproxy to proxy port 5555 to this container port (5000)
  environment:
    - VIRTUAL_HOST='example.com:4444, example.com:5555'

app2:
  image: app1
  expose:
    - '4000' # I want haproxy to proxy port 6666 to this container port (4000)
    - '5000' # I want haproxy to proxy port 7777 to this container port (5000)
  environment:
    - VIRTUAL_HOST='example.com:6666, example.com:7777'

lb:
  image: dockercloud/haproxy
  links:
    - app1
    - app2
  ports:
    - 4444:4444
    - 5555:5555
    - 6666:6666
    - 7777:7777

Unfortunately, haproxy performs a roundrobin scheduling to one of the container ports. Instead, I need haproxy to proxy port 4444 to app1:4000, 5555 to app1:5000, 6666 to app2:4000, and 7777 to app2:5000.

from dockercloud-haproxy.

tifayuki avatar tifayuki commented on July 26, 2024

I don't think you can do this with the currently implementation of dockercloud/haproxy.

What you can do is the use different ports on the two different apps and then use TCP load balancing.

from dockercloud-haproxy.

Bekt avatar Bekt commented on July 26, 2024

Even then, dockercloud/haproxy only exposes one port per container, is that right?

from dockercloud-haproxy.

tifayuki avatar tifayuki commented on July 26, 2024

dockercloud/haproxy assumes that each container runs only one application.

If your container exposes more than one port, you need either 1) use EXCLUDE_PORTS to disable the port you don't want to publish, or 2) use TCP_PORTS to load balance the ports in TCP mode.

from dockercloud-haproxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.