2

I have a NodeJS application packed in a Docker container from which I send email to smtp.gmail.com (using nodemailer npm library). The same container (I mean same image pulled from same registry) works on my Macbook, but throws timeout error on my Ubuntu VPS. I tried to ping smtp.gmail.com from Ubuntu container using docker exec..., and the ping works fine. I wonder what is the problem. Here are the details -

My Macbook:

  • OS: MacOS High Sierra (Version 10.13.6)
  • Docker: Version 18.06.1-ce, build e68fc7a

Ubuntu VPS:

  • OS: Ubuntu 16.04.5 LTS
  • Docker: Version 18.06.1-ce, build e68fc7a

Error:

On Ubuntu machine I start the container using command docker run -p 7656:7656 fb. And the error I get is -

{ Error: Connection timeout
    at SMTPConnection._formatError (/docker-training/node_modules/nodemailer/lib/smtp-connection/index.js:606:19)
    at SMTPConnection._onError (/docker-training/node_modules/nodemailer/lib/smtp-connection/index.js:579:20)
    at Timeout._connectionTimeout.setTimeout (/docker-training/node_modules/nodemailer/lib/smtp-connection/index.js:261:18)
    at ontimeout (timers.js:478:11)
    at tryOnTimeout (timers.js:302:5)
    at Timer.listOnTimeout (timers.js:262:5) code: 'ETIMEDOUT', command: 'CONN' }

My Docker file -

FROM node:9.2.0
RUN mkdir /docker-training
WORKDIR /docker-training
COPY  . ${WORKDIR}
RUN ["npm", "install"]
EXPOSE 7656
ENTRYPOINT ["npm", "start"]

Any help is appreciated.

tgogos
  • 23,218
  • 20
  • 96
  • 128
Jahid Shohel
  • 1,395
  • 4
  • 18
  • 34

1 Answers1

0

The network settings seem to be at fault. Please try to run the container with --network host and if it works, you'll need to alter the docker network settings to allow the connections from container to docker host

Jan Myszkier
  • 2,714
  • 1
  • 16
  • 23
  • janmyszkier: Thanks. The `--network host` works for now, but the problem is that's just "Linux only" solution. Host network is not supported on Windows and Mac. – Jahid Shohel Aug 31 '18 at 12:06
  • without the code I cannot really solve your issue, but please have a look at this, and other similar topics: https://stackoverflow.com/questions/17770902/forward-host-port-to-docker-container – Jan Myszkier Aug 31 '18 at 12:09