简体   繁体   English

泊坞窗。 从主机发送邮件

[英]Docker. Send mail from host

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容器发送邮件。 Docker says "port is already in use" when I try to map it to 25 port in run command: 当我尝试在运行命令中将其映射到25端口时,Docker表示“端口已在使用中”:

run -ti -p 25:25 container

How I can achieve the goal? 我如何实现目标? Host is Centos, docker uses Ubuntu. 主机是Centos,码头工人使用Ubuntu。

Using port forwarding with docker container you forward container's port to host. 将端口转发与docker容器一起使用,可以将容器的端口转发到主机。 So you have port 25 already in use on host by mail server. 因此,邮件服务器在主机上已经使用了端口25。 Here you need to forward port from host to the container: 在这里,您需要将端口从主机转发到容器:

Forward host port to docker container 将主机端口转发到Docker容器

The easiest way is to use --net=host option: 最简单的方法是使用--net=host选项:

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: 因此,如果主机上已经有一个应用程序在侦听端口25,则可以停止该应用程序,也可以将容器配置为侦听其他主机端口,例如:

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. 这将导致端口从主机端口2525映射到容器端口25。如果您不需要从容器接收邮件,则可以完全删除此端口映射,这仍将允许您发送出站邮件。

If you don't know what is using port 25 on the host, you can look this up with a netstat command: 如果您不知道主机上正在使用端口25的内容,则可以使用netstat命令查找它:

sudo netstat -lntp

Note that the sudo is required if you want to see the process that is listening on the port. 请注意,如果您想查看正在端口上侦听的进程,则必须使用sudo。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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