localhost 또는 172.17.0.1을 사용하는 SMTP 설정이 작동하지 않습니다. 디버깅 방법은?

How to set SMTP config to use localhost?에서 이어지는 토론입니다:

호스트 머신에서 실행 중인 Protonmail Bridge에 연결을 시도하고 있지만 connection refused 오류가 발생합니다. 제 설정은 다음과 같습니다:

  DISCOURSE_SMTP_ADDRESS: 172.17.0.1
  DISCOURSE_SMTP_PORT: 1025

이제 nmap 테스트를 해보겠습니다:

호스트 머신에서 nmap 127.0.0.1을 실행하면 다음과 같은 출력이 나옵니다:

Nmap scan report for localhost (127.0.0.1)
Host is up (0.000010s latency).
Not shown: 997 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
1025/tcp open  NFS-or-IIS
1042/tcp open  afrog

docker 컨테이너에서 nmap 172.17.0.1을 실행하면 1025 포트가 출력되지 않습니다.

또한 제 app.yml 파일의 expose 섹션에서 다음을 시도해 보았습니다:

172.17.0.1:1025:1025

하지만 그 결과 “the port is already in use”(포트가 이미 사용 중) 오류가 발생하여 docker 컨테이너가 시작되지 않았습니다.

마지막으로, openssl을 사용하여 localhost에서 연결을 시도해 보면:

openssl s_client -connect 127.0.01:1025 -starttls smtp

이것은 잘 작동합니다. 하지만 docker 컨테이너에서 시도하면 작동하지 않습니다:

openssl s_client -connect 172.17.0.1:1025 -starttls smtp

호스트 머신에서 ss로 확인해 보면:

ss -plnt
State  Recv-Q  Send-Q  Local Address:Port  Peer Address:Port  Process
LISTEN   0      4096       127.0.0.1:1025      0.0.0.0:*    users:(("proton-bridge",pid=953,fd=12))

제가 어디를 잘못하고 있나요?


이 stackoverflow 답변에서 발견한 내용이 하나 있습니다:

  • INADDR_ANY(즉, 0.0.0.0)에서 리스닝하거나 docker0 인터페이스에서 명시적으로 리스닝하는 호스트 서비스에만 액세스할 수 있습니다.

우선, 기본 출력을 제공한다고 생각하는 iptables --list를 확인해 보았습니다:

iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy DROP)
target     prot opt source               destination
DOCKER-USER  all  --  anywhere             anywhere
DOCKER-ISOLATION-STAGE-1  all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain DOCKER (1 references)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:https
ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:http

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

Chain DOCKER-ISOLATION-STAGE-2 (1 references)
target     prot opt source               destination
DROP       all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

Chain DOCKER-USER (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere

이제, 127.0.0.1:1025에서 리스닝 중인 Protonmail Bridge 서비스가 Docker 컨테이너에서 온 것이 아니기 때문에(정확히 127.0.0.1에서 온 것이 아니기 때문에) 연결을 거부하는 것은 아닌지 궁금해지고 있습니다.

결국 트래픽을 재 yö정해야 하는 것으로 나타났습니다. 자세한 내용은 여기에서 확인하세요: