I want to run a SMTP server on a Docker container in Elastic Beanstalk, so in my Dockerfile I have exposed the port 25 (and no other ports)
EXPOSE 25
I also edited the beanstalk load balancer (using EC2 web admin) and added port 25 to it:
| LB Protocol | LB Port | Instance Protocol | Instance Port | SSL |
| TCP | 25 | TCP | 25 | N/A |
....
And edited the security group of the instance to allow inbound TCP traffic to port 25 (allowed all locations to be able to connect to the instance directly).
Doesn't seem to work though. If I use the same Dockerfile in Virtualbox (using option -p 25:25
) I can connect to the port 25 through the host machine and the SMTP server is listening. If I run the container in Elastic Beanstalk using the before-mentioned configuration I can't connect to the port 25 neither using the load balancer or directly the EC2 instance.
Any ideas what I'm doing wrong here?
Instead of editing the Load Balancer configuration directly from EC2 web admin it is recommended you do it using elasticbeanstalk ebextensions because those changes persist for your environment even if your EC2 instances in the auto-scaling group are replaced.
Can you try the following? Create a file "01-elb.config" in a folder called
.ebextensions
in your app source with the following contents:This file is in YAML format and hence indentation is important. The option setting ('aws:cloudformation:template:parameter', 'InstancePort') sets the instance port to 25 and also modifies the security group to make sure that port 25 is accessible by the load balancer.
This file is overriding the default Load Balancer Resource created by Elastic Beanstalk with two listeners both having instance port set to 25. Hope that helps.
Read more about customizing your environment with ebextensions here. Can you try creating a new environment with the above file in
.ebextensions/01-elb.config
file in the appsource directory? Let me know if you run into any issues.