简体   繁体   English

如何使用Docker覆盖配置文件

[英]How to overwrite a configuration file with Docker

I have a Docker project with the following structure: 我有一个具有以下结构的Docker项目:

.
├── config
└── Dockerfile

where the Dockerfile is Dockerfile在哪里

FROM alpine:latest
EXPOSE 8118
RUN apk --update add privoxy
COPY config /etc/privoxy/config
CMD ["privoxy", "--no-daemon"]

and the config contains the two lines 并且config包含两行

listen-address 0.0.0.0:8118
forward-socks5 / tor:9050 .

In the container, I would like to make the Privoxy configuration file, of which the default location is /etc/privoxy (cf. https://www.privoxy.org/user-manual/config.html ), into the 'local' config file, which is what I'm trying to achieve with the COPY directive. 在容器中,我想将Privoxy配置文件(默认位置为/etc/privoxy (参见https://www.privoxy.org/user-manual/config.html ))放入“本地config文件,这就是我要使用COPY指令实现的目标。

However, if I docker build --tag my_privoxy . 但是,如果我docker build --tag my_privoxy . followed by docker run my_privoxy , I see the following error message: 其次是docker run my_privoxy ,我看到以下错误消息:

2017-05-02 10:40:29.371 7f2ce5f00b48 Info: Privoxy version 3.0.24
2017-05-02 10:40:29.371 7f2ce5f00b48 Info: Program name: privoxy
2017-05-02 10:40:29.371 7f2ce5f00b48 Fatal error: can't check configuration file '//config':  Invalid argument

I don't see how the expected location of the configuration file ends up as '//config' in the container; 我看不到配置文件的预期位置在容器中如何以'//config'结尾。 the use of COPY seems to me consistent with https://docs.docker.com/engine/reference/builder/#copy . 在我看来, COPY的使用与https://docs.docker.com/engine/reference/builder/#copy一致。 What is wrong with the above Dockerfile ? 上面的Dockerfile什么问题?

is /etc/privoxy/config a directory? /etc/privoxy/config是目录吗? if no, then your command should be like 如果没有,那么你的命令应该像

COPY config /etc/privoxy/

According to privoxy --help , the command accepts a [configfile] optional input. 根据privoxy --help ,该命令接受[configfile]可选输入。 So I changed the last line to 所以我将最后一行更改为

CMD ["privoxy", "--no-daemon", "/etc/privoxy/config"]

and it works. 而且有效。 (I still don't understand why it doesn't work without the configfile input though, as /etc/privoxy/config should be the default). (我还是不明白为什么它不没有工作configfile输入不过,因为/etc/privoxy/config应该是默认值)。

In the container, I would like to make the Privoxy configuration file 在容器中,我要制作Privoxy配置文件

You could mount a volume into the folder with the configuration you want. 您可以使用所需的配置将卷装入文件夹。 This would be done with docker run -v hostFolder:containerFolder imagename . 这可以通过docker run -v hostFolder:containerFolder imagename来完成。 This however will not result in a new image with the configuration instead you will get a container with the configuration you want. 但是,这不会导致配置产生新的映像,而是会得到一个包含所需配置的容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM