在Dockerfile中分开特定配置 [英] Separate specific configuration in Dockerfile
问题描述
这是我的Docker文件:
FROM debian:wheezy
RUN apt-get update&& apt-get install -y wget&&& \
echodeb http://packages.dotdeb.org wheezy all>> /etc/apt/sources.list&&& \
echodeb-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\\\
daemon 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 /
....
这样,我想在docker注册表中创建一个自动构建(从我的bitbucket帐户)。在构建过程中,Docker需要有一个 nginx / server.conf
和 / nginx / extra_conf
的路径。 IMHO,这个配置是非常用户/项目特定的,不应该包含在这个级别(也可能不是在版本控制中)。
我该怎么做更通用?
我以为使用 ONBUILD
指令添加我的文件并创建一个 Dockerfile
孩子。问题是,它创造了无用的继承水平。
Thx,
注意
您可以使用卷,因此您可以在主机上的 /path/to/nginx/conf.d
上存储配置文件:
docker run -v /path/to/nginx/conf.d:/etc/nginx/conf.d:ro nginx
卷也适用于常规文件。
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
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.
这篇关于在Dockerfile中分开特定配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!