0

I am trying to create a postfix container.

What I want to do is to send emails from another container.

Here is what I've done:

FROM ubuntu:latest

RUN apt-get update && apt install -y postfix

COPY main.cf /etc/postfix/main.cf
COPY master.cf /etc/postfix/master.cf
COPY mynetworks /etc/postfix/mynetworks
COPY mydestinations /etc/postfix/mydestinations

CMD service postfix restart && tail -f /dev/null

It works but I want to improve it.

  • I don't want any external configuration files dependencies: master.cf and main.cf. Is there a way, to say, in a Dockerfile: remove this line from main.cf and add this one instead. I have tried to do it with bash script but it is ugly. Is there a Dockerfile command to say: "I want to set this variable in this configuration file with this value" ?

  • I need to put my second docker container IP in /etc/postfix/mynetworks file. But this IP address may change other time. I have tried to put its hostname in /etc/postfix/mynetworks but it doesn't work. How can I do ?

Thanks

1 Answer 1

0

Replacing lines in a file directly from Dockerfile

For the lines that exist and should be replaced you could invoke sed with RUN, e.g.,

RUN sed -i \
    "s|^mynetworks\s=.*$|mynetworks = cidr:/etc/postfix/mynetworks|" \ 
    /etc/postfix/main.cf

Use another authentication than IP address

If you would have to put dynamic IP addresses in your mynetworks and you cannot trust an entire CIDR subnet, you are really using a poor authentication method for the purpose. Instead of trusting IP addresses, you should use, e.g., password authentication (SASL) or client certificates.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .