Coder Social home page Coder Social logo

Comments (3)

Bekt avatar Bekt commented on July 26, 2024

I would be interested in this as well.

The work around for this is something like:

  web:
    build: 'web/'
    ports:
     - 8080
    environment:
      - 'VIRTUAL_HOST=*:8080'

However, this is not ideal because:

  1. Binding a wildcard domain is bad
  2. If my container exposes multiple ports (8080, 9090) I cannot bind 8080 to something some other port, say 4444.

Would like to hear from others as well.

from dockercloud-haproxy.

leibowitz avatar leibowitz commented on July 26, 2024

a little late, but I think your (working) configuration should work fine for your use case.

haproxy:
  ports:
    - "8080:80"

This only means haproxy internal port is 80, and the external (public one, aka what you use in your http request) is 8080.

You shouldn't care about what haproxy uses internally (port 80), as this is not exposed anywhere and will not conflict with any other container or services running on that port.

If you wish to expose your web service on a different port, feel free to change the 8080 part. The 80 part should not be changed.

Hope that makes sense

from dockercloud-haproxy.

motin avatar motin commented on July 26, 2024

Haproxy needs to be configured to be published on the same port as it uses internally, since it matches the port from VIRTUAL_HOST against the Host-header of the request.

Working config:

  1. docker-compose.yml:
# Docker compose configuration for local development
version: '2'
services:

  # The local version of the public haproxy router, used to test blue/green deployments locally
  router:
    image: dockercloud/haproxy:1.6.2
    links:
      - web
    ports:
      - "8080:8080"
      # Publish stats port
      - "1936:1936"
    environment:
      STATS_AUTH: stats:n3v3rg0nnAg1v3y0uup
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  web:
    image: dockercloud/hello-world
    ports:
      - "80:80"
    environment:
      VIRTUAL_HOST: 'localhost:8080'
  1. docker-compose up
router_1  | INFO:haproxy:dockercloud/haproxy 1.6.2 is running outside Docker Cloud
router_1  | INFO:haproxy:Haproxy is running by docker-compose, loading HAProxy definition through docker api
router_1  | INFO:haproxy:dockercloud/haproxy PID: 7
router_1  | INFO:haproxy:=> Add task: Initial start - Compose Mode
router_1  | INFO:haproxy:=> Executing task: Initial start - Compose Mode
router_1  | INFO:haproxy:==========BEGIN==========
router_1  | INFO:haproxy:Linked service: dockercloudhaproxyportconfig_web
router_1  | INFO:haproxy:Linked container: dockercloudhaproxyportconfig_web_1
router_1  | INFO:haproxy:HAProxy configuration:
router_1  | global
router_1  |   log 127.0.0.1 local0
router_1  |   log 127.0.0.1 local1 notice
router_1  |   log-send-hostname
router_1  |   maxconn 4096
router_1  |   pidfile /var/run/haproxy.pid
router_1  |   user haproxy
router_1  |   group haproxy
router_1  |   daemon
router_1  |   stats socket /var/run/haproxy.stats level admin
router_1  |   ssl-default-bind-options no-sslv3
router_1  |   ssl-default-bind-ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:DHE-DSS-AES128-SHA:DES-CBC3-SHA
router_1  |   debug
router_1  | defaults
router_1  |   balance roundrobin
router_1  |   log global
router_1  |   mode http
router_1  |   option redispatch
router_1  |   option httplog
router_1  |   option dontlognull
router_1  |   option forwardfor
router_1  |   timeout connect 5000
router_1  |   timeout client 50000
router_1  |   timeout server 50000
router_1  | listen stats
router_1  |   bind :1936
router_1  |   mode http
router_1  |   stats enable
router_1  |   timeout connect 10s
router_1  |   timeout client 1m
router_1  |   timeout server 1m
router_1  |   stats hide-version
router_1  |   stats realm Haproxy\ Statistics
router_1  |   stats uri /
router_1  |   stats auth stats:n3v3rg0nnAg1v3y0uup
router_1  | frontend port_8080
router_1  |   bind :8080
router_1  |   reqadd X-Forwarded-Proto:\ http
router_1  |   maxconn 4096
router_1  |   acl is_websocket hdr(Upgrade) -i WebSocket
router_1  |   acl host_rule_1 hdr(host) -i localhost
router_1  |   acl host_rule_1_port hdr(host) -i localhost:8080
router_1  |   use_backend SERVICE_dockercloudhaproxyportconfig_web if host_rule_1 or host_rule_1_port
router_1  | backend SERVICE_dockercloudhaproxyportconfig_web
router_1  |   server dockercloudhaproxyportconfig_web_1 dockercloudhaproxyportconfig_web_1:80 check inter 2000 rise 2 fall 3
router_1  | INFO:haproxy:Launching HAProxy
router_1  | INFO:haproxy:HAProxy has been launched(PID: 13)
router_1  | INFO:haproxy:===========END===========
  1. Connect successfully against localhost:8080
$ curl -v http://localhost:8080
* Rebuilt URL to: http://localhost:8080/
*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.45.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.10.1
< Date: Thu, 26 Jan 2017 08:21:15 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< X-Powered-By: PHP/5.6.23
<
<html>
<head>
	<title>Hello world!</title>
	<link href='//fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
	<style>
	body {
		background-color: white;
		text-align: center;
		padding: 50px;
		font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
	}

	#logo {
		margin-bottom: 40px;
	}
	</style>
</head>
<body>
	<img id="logo" src="logo.png" />
	<h1>Hello world!</h1>
	<h3>My hostname is d797b1d77f38</h3>	</body>
</html>
* Connection #0 to host localhost left intact

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.