Docker Community Forums

Share and learn in the Docker community.

Revisited - Ability to statically assign persistent ports through the ELB

I had made a lengthy post a while back about wanting to statically assign ports on my ELB but took it down thinking I could accomplish this by editing the Docker for AWS CloudFormation template. I have not had any luck doing that so far. The short of it is - I have my containers listening on non-standard ports (eg nginx listening on port 1989 instead of 80) and my goal was to have a static mapping at the ELB so that when users connect to the ELB on port 443 (ssl) that connection will be translated to the docker swarm cluster on port 1989. I can manually configure the ELB and this configuration works great UNTIL I discard the containers and spin up new ones (using the same published port of 1989). The moment I remove the containers, all port mappings on the ELB (including my static 443 to 1989 mapping) are removed and once the containers is started, only the dynamic port mapping for the published port is there (load balancer port = 1989 and Instance Port = 1989).

I basically need a way to configure the ELB with port mappings of my choice and have them stay there regardless of how many times I shutdown, remove and spin up new containers.

Is this possible via editing the cloudformation template?

1 Like

Did you manage to solve this problem?

yes I did but then ran into another unexpected problem. My solution was to configure my CI server (jenkins) to make AWS api calls to reconfigure the load balancer with the appropriate listener ports and ssl certs. Basically near the end of the build, Jenkins would remove the auto-created docker swarm service listener ports and add in the non-standard ports that I needed. This process worked great BUT the major problem I started finding was that even if I didn’t make any changes to my swarm (eg no new deployments etc.) eventually (and sporadically) the listener ports on the ELB would revert back to the auto-created docker swarm service ports (removing my statically configured ports). I didn’t see this previously as I was doing multiple builds a day - it wasn’t until we started nearing the end of the project (with builds diminishing to once a week) that I started noticing the sporadic reset of the ports. I opened up an issue on the Docker for AWS github site - which the Docker engineers are actively engaged with. I think they are going to address this in an upcoming release.