Separate specific configuration in Dockerfile

霸气de小男生 提交于 2019-12-25 03:32:22

问题


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.



来源:https://stackoverflow.com/questions/30383701/separate-specific-configuration-in-dockerfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!