简体   繁体   中英

Docker use host port without mapping port

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM