Spring boot on docker container network unstable - java

I have a spring boot app that runs docker container on top of Linux.
The app is sending bulk email to internal employees.
We have around 10 thousand emails to be sent every night.
Each email took about 5ms to sent.
The mail server and docker spring is in same company network
The problem is, the mail application in docker sometimes cannot connect to mail server.
Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: xxx.xxx.xxx, port: 25, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: xxx.xxx.xxx, port: 25, response: -1
But if I run the spring boot application without docker, from same machine, everything works fine (all emails were sent and no error message logged)
The docker network seems unstable.
Is this needs tuning or something?
This is my dockerfile to create the container
FROM openjdk:11-jre-stretch
COPY cacerts /docker-java-home/lib/security
RUN mkdir conf
VOLUME /tmp
EXPOSE 8002
ARG JAR_FILE=build/libs/mailman-1.1.jar
ADD ${JAR_FILE} mailman.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/mailman.jar"]

Related

GCP GKE SMTP port 465 connection reset

I've got a Spring Boot Java application that sends emails via SMTP port 465 (non-gmail email). My configuration:
spring:
mail:
host: ssl0.ovh.net
port: 465
username: mailer#external.pl
password: mailerPassword
Locally everything works fine. When I deploy it on GCP Kubernetes cluster I've got a connection reset exception. I've read that GCP recommends some external paid providers but for my solution it's too much of a complication. Additionally I know that port 25 is disabled on GCP -> I've got port 465.
I've tried to simply add a firewall egress rule to enable traffic on every port for my VPC but it also didn't help.
What am I missing? Can anybody help my solve this puzzle?
Additional info:
My Java application is served as a simple deployment in k8s. It is exposed through LoadBalancer service on port 80.
Making a curl from given managed pod works - I receive a correct 2xx responses from various sites.
It turned out that my config map port changed from 456 to 465 but I forgot to restart the app. It works like a charm without any NAT configuration or firewall rules. Thanks for your support.

unable to send email on docker container from port 465

I tried to send an email from port 465, it works well on IDEA. But when I deployed it on docker, the email send failed. The error message is:
javax.mail.MessagingException: Could not connect to SMTP host: smtpdm.aliyun.com, port: 465, response: -1
Then I tried to change the port to 25, the email sent success.
Change the smtp server seems nothing better.
How can I send mail from port 465 on docker container?
make sure that the port is available on the host machine and ports are mapped correctly when you start the docker image. also, make sure that postfix is installed in your docker image and is active (sudo postfix status or sudo systemctl status postfix).
if both of theses conditions are met but it still don't work please also Try to set these values to:
smtp_tls_wrappermode = yes
smtp_tls_security_level = encrypt
in /etc/postfix/main.cf in the docker container.

Fargate: Sending email to private smtp server on port 25

I'm using AWS Fargate as my container platform. My container base image is openjdk:8-alpine and the application is a spring-boot app. I'm attempting to use JavaMailSender to send emails over a vpn tunnel to our internal SMTP server on port 25. This works while testing the container locally, using the same SMTP server.
I've mainly used this guide https://www.baeldung.com/spring-email for the email functionality in my spring boot app.
If I add the following commands to the docker entrypoint I test hostname resolving and telnet connection. The host and dig commands always work. Sometimes telnet works and other times it will timeout, causing a re-deployment of the container. When sending emails I see the same behavior. Some emails will send while others fail due to a timeout connecting to the SMTP server.
## Dockerfile
FROM openjdk:8-alpine
COPY core/target/app.jar /app/app.jar
WORKDIR /app
CMD CMD host $my_smtp_server \
&& dig $my_smtp_server \
&& telnet $my_smtp_server 25 \
&& java -jar $app.jar
EXPOSE 8080 25
## application.properties
# Mail config
#------------
spring.mail.default-encoding=UTF-8
spring.mail.host=$my_smtp_server
spring.mail.port=25
spring.mail.protocol=smtp
spring.mail.properties.mail.smtp.starttls.enable=false
spring.mail.properties.mail.smtp.starttls.required=false
spring.mail.properties.mail.smtp.auth=false
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000
#------------
Emails should send every time I invoke the function in my application.

Host Ip binding failed

I am trying to connect my genymotion emulator to my localhost. After reading an article I got to know that my emulator is running on virtual host so I need to run my application in the same network
So emulator is on ip 192.168.20.101 So I tried to keep my server on 192.168.20.5
I am using dropwizard server. I got an error java.net.BindException: Cannot assign requested address: bind
I used following code to change my yml file
server:
applicationConnectors:
- type: http
bindHost: 192.168.20.5
port: 8090
adminConnectors:
- type: http
bindHost: 192.168.20.5
port: 8091
I am not sure you can bind IP in inside VirtualBox network. What you can do is configure your device to run in bridge mode, like this:
This way the device runs in the same network as your host, so you can easily access localhost or other machines.

Connection refused from docker (in swarm)

I have a docker swarm setup with services registered in an overlay network. Comunication between services is working fine however I get a "Connection refused" from one of my services that connects to an external DB. The service is a Java based application (spring boot).
The connection is defined with its IP (jdbc:mysql://192.168.130.141:3306/database?autoReconnect=true)
I have checked that I can ping the server from the container docker exec -it e093 ping 192.168.130.141 gives expected answer
I have rechecked (4 times) my credentials
I can connect to the DB from the host
Host is Ubuntu 16.04.4 LTS
I am running docker 18.03.0-ce and the exact error is
java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_151]
I'll skip the full stack trace here.
Any help would be greatly appreciated
--EDIT--
Let me clarify that the database is a Galera cluster and the IP I try to connect to is the load balancer (HAProxy) in front of it. I know the setup works as I have other applications connecting to the cluster in this matter as well as the service itself (when not in a docker container).
So, as far as I can tell, my connection informations are correct but it doesn't connect from inside docker services.
Can you show your docker-compose.yml? In the ports you have to expose the port that you need to access.
ports:
- 3306:3306
You can install telnet to test if the port is open using this commands inside the container
docker container ls
docker exec -it conainerid bash
apt-get update
apt-get install telnet

Categories

Resources