Setting up SMTP server for your app in a container Setting up SMTP server for your app in a container docker docker

Setting up SMTP server for your app in a container


If you want the SMTP server to just be reachable from the other container and not from the outside, no need to map the port.

Using docker-compose, all defined containers will automatically be added to a network in which containers can reach each other by their name (see https://docs.docker.com/compose/networking/). If your custom "default" network is a bridge network, this will work as well.

That means, your SMTP container will directly be reachable at smtp:25 from other containers (i.e. its internal port and internal hostname instead of the host port and publicly routable IP address of your docker host).

Nobody else will be able to use your SMTP server like that. I think this might lead to problems with recipients not accepting the emails sent by it (see https://serverfault.com/q/364473). @David Maze has a point in saying that it's probably better to use a public/official mail provider anyways.


I think the issue is that you have something else on the host that is already listening on that port

Try to find out what ports on the host are listening with https://www.cyberciti.biz/faq/how-do-i-find-out-what-ports-are-listeningopen-on-my-linuxfreebsd-server/


Use some other port on the host:

version: '3'services:  push:    image: emailService    ports:    - "9602:9602/tcp"    networks:    - default    build:      context: ./      dockerfile: Dockerfile      args:      - "TARGET=build"    depends_on:    - gearmand    - smtp  smtp:    image: catatnight/postfix:latest    ports:    - "2525:25"    networks:    - default  gearmand:    image: <path>/<to>/gearmand:latest    ports:    - "4730:4730/tcp"    networks:    - default