今天在启动一个docker 运行nginx实例,在挂载目录时,出现访问静态目录时,权限不够

执行的命令是:

 docker run 
--name my-nginx 
-d -p 80:80 
--restart=always  
-v /cloud/nginx/webroot:/usr/share/nginx/html:rw 
-v /cloud/nginx/log:/var/log/nginx 
-v /cloud/nginx/config/nginx.conf:/etc/nginx/nginx.conf:ro 
-d nginx  

说明:

1.其中/cloud/nginx/webroot 是我的宿主机中目录,用于存放静态面页

2./cloud/nginx/log  存放日志

3./cloud/nginx/config/nginx.conf  为nginx的配置文件

docker run 
--name my-nginx 
-d -p 80:80 
--restart=always  
-v /cloud/nginx/webroot:/usr/share/nginx/html:rw 
-v /cloud/nginx/log:/var/log/nginx 
-v /cloud/nginx/config/nginx.conf:/etc/nginx/nginx.conf:ro 
-d nginx

使用查看日志命令显示如下:

2018/02/02 02:45:12 [error] 5#5: *1 "/usr/share/nginx/html/index.html" is forbidden (13: Permission denied), client: 10.11.3.51, server: localhost, request: "GET / HTTP/1.1", host: "10.11.3.86"
2018/02/02 02:45:12 [error] 5#5: *1 "/usr/share/nginx/html/index.html" is forbidden (13: Permission denied), client: 10.11.3.51, server: localhost, request: "GET / HTTP/1.1", host: "10.11.3.86"
后发现是宿主机的目录权限不够,所以果断加上 参数:

--privileged=true
完整命令如下:

docker run 
--name my-nginx 
-d -p 80:80 
--restart=always  
--privileged=true  
-v /cloud/nginx/webroot:/usr/share/nginx/html:rw 
-v /cloud/nginx/log:/var/log/nginx 
-v /cloud/nginx/config/nginx.conf:/etc/nginx/nginx.conf:ro 
-d nginx

加上启动容器,访问就0k了 




Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐