我使用docker容器,并为nginx构建了一个。
我将用index.html更改nginx的主页。
我怎样才能告诉我的Nginx容器在哪里找到我的自定义index.html并用我的索引替换他自己的index.html?
最佳答案
您只需在Dockerfile中放入 COPY
command或 ADD
command,即可将index.html
文件复制到NGiNX提供的文件(由root
指令定义,例如/data/www/index.html
)
COPY <src>... <dest>
ADD <src>... <dest>
这里:
COPY /path/to/your/index.html /data/www/index.html
ADD /path/to/your/index.html /data/www/index.html
注意,
RUN
或COPY
优于ADD
:The first encountered
ADD
instruction will invalidate the cache for all following instructions from the Dockerfile if the contents of<src>
have changed.
This includes invalidating the cache forRUN
instructions.
这就是suggestion made in the comments更好的原因:
if you have few changes
RUN sed -i -e"s/aaa/bbb" /data/www/index.html
如果您进行了许多更改,
ADD
仍然是有效的选项(首先尝试COPY
),但是请尝试将其放在dockerfile的末尾,而不是开头或中间。
关于nginx - Nginx Docker的容器:使用自定义index.html设置默认主页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29535153/