1

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!
Emran
  • 544
  • 7
  • 26
  • Could you run successfully without custom html file? Have you mapped 80 port ? – Andrea Sep 20 '19 at 18:29
  • @Andrea Port is OK as I connect and see the nginx 403 message! But, without the index.html the same error happens. – Emran Sep 20 '19 at 19:11

1 Answers1

1
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

HARSH MODI
  • 71
  • 5
  • It means the nginx:latest is buggy and wont work? However, I accepted the answer, as bypassed my problem. Thanks – Emran Sep 21 '19 at 07:52