I can send mails from host, using mail:
mail -s "Hooray" smb@example.com < /dev/null
But I want to send mails from docker container using host server. Docker says "port is already in use" when I try to map it to 25 port in run command:
run -ti -p 25:25 container
How I can achieve the goal? Host is Centos, docker uses Ubuntu.
Using port forwarding with docker container you forward container's port to host. So you have port 25 already in use on host by mail server. Here you need to forward port from host to the container:
Forward host port to docker container
The easiest way is to use --net=host
option:
docker run --rm -it --net=host container mail -s "Hooray" smb@example.com < /dev/null
You can't listen on the same port with multiple applications. So if there's already an application on the host listening on port 25, you can either stop that application, or configure your container to listen on a different host port, eg:
run -ti -p 2525:25 container
That causes the port to be mapped from the host port 2525 to the container port 25. If you don't need to receive mail from the container, you can remove this port mapping entirely, that will still allow you to send outbound messages.
If you don't know what is using port 25 on the host, you can look this up with a netstat command:
sudo netstat -lntp
Note that the sudo is required if you want to see the process that is listening on the port.
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.