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 chown
ing to www-data
and nginx
. Also chmod
ing +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?
I also tried without the custom html file.
This simple Dockerfile yet responds the same:
FROM nginx
# Just it!
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