How can I make /etc/hosts writable by root in a Docker Container?

后端 未结 4 641
花落未央
花落未央 2021-01-31 18:43

I\'m new to using docker and am configuring a container.
I am unable to edit /etc/hosts (but need to for some software I\'m developing). Auto-edit (via sudo or root) of the

4条回答
  •  忘掉有多难
    2021-01-31 19:15

    I have recently stumbled upon a need to add an entry into /etc/hosts file as well (in order to make sendmail working).

    I ended up making it part of the Dockerfile's CMD declaration like this:

    CMD echo "127.0.0.1 noreply.example.com $(hostname)" >> /etc/hosts \
        && sendmailconfig \
        && cron -f
    

    So it effectively is not a part of the image, but it is always available after creating a container from the image.

提交回复
热议问题