Romas Augustinavičius
Romas Augustinavičius

Reputation: 443

Java mail client can't reach SMTP server from Docker container

I have created simple Java application which sends emails. It's working properly when I running it from my IDE, but when running it inside a Docker container it can't reach the remote SMTP server. I'm using

docker run -d -p 25:25 [image]:[tag]

to expose port 25 when starting the container. Does anyone has an idea why the mail client can't connect?

Upvotes: 2

Views: 2565

Answers (1)

David
David

Reputation: 8206

I think you are confusing the point of the port mapping. This is to allow the host to bind the specified port on the given network interface to the port in the container. In your case you are trying to connect to port 25 i presume on another remote host.

If the app works when run in the IDE I'd assume either an issue resolving the SMTP server or a problem with the address on which the SMTP server is listening.

Are you running the SMTP server locally or connecting to one that is resolvable via public DNS? If you use docker exec to enter the running container can you telnet to the SMTP server?

Upvotes: 1

Related Questions