我正在使用Docker设置nginx服务器。如果我在all-html中添加了新文件/目录,是否需要将该内容动态加载到nginx(无需重新加载nginx)?
仅当再次重建图像(没有缓存)时,我才能加载新内容。有什么方法可以设置nginx配置以动态加载内容而无需重建docker镜像?
Dockerfile
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y nginx
RUN rm /etc/nginx/nginx.conf
ADD nginx.conf /etc/nginx/
ADD web /usr/share/nginx/html/
ADD web /var/www/html/
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
EXPOSE 90
CMD service nginx start
nginx.conf
worker_processes 1;
events { worker_connections 1024; }
http {
include mime.types;
sendfile on;
server {
root /usr/share/nginx/html/;
index index.html;
server_name localhost;
listen 90;
location /all-html {
autoindex on;
}
}
}
ls web/
all-html icons index.html mime.types
ls web/all-html/
1.html ntf.zip 2.html
答案 0 :(得分:1)
使用VOLUME
挂载Web目录,以便文件同步,并且Nginx动态加载内容,而无需重建docker镜像。
您可以将卷安装在Dockerfile中,甚至可以在启动容器时安装,如下所示。
-v web:/var/www/html/
答案 1 :(得分:0)
您可以将主机目录作为卷安装在容器内,在主机目录中进行更改(它们将在容器内传播),然后docker exec ... nginx -s reload OR kill -s HUP
,是您提到的bash代码段吗?或者,您可以在容器内运行另一个进程,该进程将定期检查更改并重新加载nginx进程。