Answer a question

I'm using nginx docker image to serve a simple index.html file.
As mentioned in the quick guid, I have a Dockerfile containing:

FROM nginx

COPY www-root-dir /usr/share/nginx/html

(www-root-dir just contains an index.html file) But when I run this image, it returns 403 Forbidden. And in logs it says:

 [error] 7#7: *2 "/usr/share/nginx/html/index.html" is forbidden (13: Permission denied),

I've searched about this and know it's about file permissions.
But what permission/owner should I set for that? I've tried chowning to www-data and nginx. Also chmoding +rwx didn't help.
My question is: What exactly should I do? And whatever the solution is, why it's not mentioned in the official docs?

Edit:

I also tried without the custom html file.
This simple Dockerfile yet responds the same:

FROM nginx
# Just it!

Answers

FROM nginx:alpine

COPY directory_containing_index  /usr/share/nginx/html

This is working fine for me.

alpine versions are very small in sizes compare to their counterparts like ubuntu. you can test it without defining your own Dockerfile like,

docker run --rm -v /directory_containing_index:/usr/share/nginx/html -p 8080:80 nginx:alpine

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐