我正在使用最新的官方nginx docker容器 。
无论何时启动容器,都会在/usr/share/nginx/html
中创build两个文件
root@ba65db04a18f:/# ls -la /usr/share/nginx/html total 16 drwxr-xr-x 2 root root 4096 Jun 28 15:38 . drwxr-xr-x 3 root root 4096 Jun 23 00:55 .. -rw-r--r-- 1 root root 537 May 30 13:03 50x.html -rw-r--r-- 1 root root 612 May 30 13:03 index.html
如何防止这些文件被创build?
我用来启动容器的命令是:
docker volume create static docker run -it --rm --name nginx -v static:/usr/share/nginx/html:ro nginx
默认configuration文件( /etc/nginx/nginx.conf
)是:
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
在/etc/nginx/conf.d
有一个名为default.conf的文件,其内容是:
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
我试着用空白文件覆盖这个default.conf
文件,用命令启动容器:
docker volume rm static docker volume create static docker run -it --rm --name nginx -v static:/usr/share/nginx/html:ro -v /path/on/host/to/blank/default.conf:/etc/nginx/conf.d/default.conf nginx
但是nginx仍然创buildindex.html
和50x.html
。 我如何让它停止?
nginx泊坞窗图像负责index.html
和50x.html
文件:
为了防止它们被创build,有必要扩展官方的nginx docker镜像并删除这些文件。
或者,还应该可以更改用于启动容器的CMD
,以便在启动nginx进程之前删除文件。