Reputation: 275
My Docker file contents are
FROM nginx
COPY /src /usr/share/nginx/html
My docker compose file contents are
version: '2'
services:
app:
build: .
image: app:1.0.0
volumes:
- ./src:/usr/share/nginx/html
ports:
- "8080:80"
I'm getting following error when run docker-compose
*1 directory index of "/usr/share/nginx/html/" is forbidden
I tried giving permission to directory -> /usr/share/nginx/html it didn't work.
I want to sync host directory with docker container.
Upvotes: 17
Views: 24805
Reputation: 59946
I was facing the same issue so the posting answer might help some else or some else looking for the same problem
I am running nginx official image.
docker run --rm --name some-nginx -p 8080:80 -v /test/html5-youtube.js/examples/:/usr/share/nginx/html -it nginx
I was getting this error.
[error] 8#8: *3 directory index of "/usr/share/nginx/html/" is *forbidden*, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost:8080"
So when I check the directory permission it was wrong.
Check the user in nginx.conf in my case it is nginx so change file permission.
cd /usr/share/nginx/html
chown nginx:nginx ./*
and then I was able to get a response from the server.
172.17.0.1 - - [30/Oct/2018:09:04:52 +0000] "GET /html5-youtube.js HTTP/1.1" 404 571 "http://localhost:8080/player.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36" "-"
Update:
Or add the permission at build time if you are not using bind volume.
RUN chown nginx:nginx /usr/share/nginx/html/*
Upvotes: 16