-1

I want to send emails from 2 separate docker containers. Both of these containers need port 25 of the host system but I can only map the port to one of those containers. When I try with the second one it throws this error: Bind for 0.0.0.0:25 failed: port is already allocated. How do I use the port of the host system without actually mapping it to one of the containers? The containers need to run on a certain network and not on the host network. I'm using Nodemailer in the docker containers btw.

Robin-Whg
  • 263
  • 4
  • 14
  • You should only need to map port 25 if you want to *receive* mails – Hans Kilian Jun 08 '22 at 14:04
  • When an external application connects to port 25 on your host, what should happen? This also doesn't appear to be a programming question and better asked on one of the other SE sites. – BMitch Jun 08 '22 at 14:08

1 Answers1

0

I figured it out. As mentioned here: From inside of a Docker container, how do I connect to the localhost of the machine?, you need to add the flag --add-host=host.docker.internal:host-gateway to the run command. That way localhost points to the docker host and not the host of the containers own network. No need to change anything in your code.

Robin-Whg
  • 263
  • 4
  • 14