Separate specific configuration in Dockerfile

2019-09-03 00:00发布

问题:

I have a design problem with a docker image. I created a simple Nginx image and add some configuration in extra files.

Here is my Dockerfile :

FROM debian:wheezy

RUN apt-get update && apt-get install -y wget && \
echo "deb http://packages.dotdeb.org wheezy all" >>  /etc/apt/sources.list && \
echo "deb-src http://packages.dotdeb.org wheezy all" >>  /etc/apt/sources.list && \
wget http://www.dotdeb.org/dotdeb.gpg && apt-key add dotdeb.gpg && \
apt-get update && apt-get install -y nginx

RUN rm -rf /var/lib/apt/lists/* && \
echo "\ndaemon off;" >> /etc/nginx/nginx.conf && \
chown -R www-data:www-data /var/lib/nginx

ADD ./nginx/server.conf /etc/nginx/sites-available/default
ADD ./nginx/extra_conf /etc/nginx/

....

With this, I want create an automated build (from my bitbucket account) in docker registry. During the build, Docker needs to have a path to nginx/server.conf and /nginx/extra_conf. IMHO, this configuration is very user/project specific and should not be include at this level (and probably not be in versionning too).

How can I do to have something more generic ?

I thought use ONBUILD instruction to add my files and create a Dockerfile child. Problem is, it creates a useless level of inheritance.

Thx, Regards

回答1:

You can use volume, thus you can store config files on /path/to/nginx/conf.d on the host:

docker run -v /path/to/nginx/conf.d:/etc/nginx/conf.d:ro nginx

Volume also works for regular files.