A
A
Alexander Pankov2021-12-01 22:17:56
linux
Alexander Pankov, 2021-12-01 22:17:56

How to solve permission issue in docker?

Hello
There is a vps on ubuntu

there created a directory
/var/www/static

inside which
-- docker-compose.yaml
--- src
---- index.html

docker is installed on vps and docker-compose
docker-compose understands containers without errors
here compose itself

version: "3"

services:
    client:
        image: nginx:latest
        ports:
            - 8000:80
        volumes:
            - ./src:/usr/share/nginx/html


starts at 8000
I go to the browser and see a 403 Forbidden error

I look at the docker-compose logs
and see this

static-client-1  | 2021/12/01 19:03:14 [error] 31#31: *1 "/usr/share/nginx/html/index.html" is forbidden (13: Permission denied), client: 46.***.***.75, server: localhost, request: "GET / HTTP/1.1", host: "194.***.***.69:8000"

static-client-1  | 46.***.***.75 - - [01/Dec/2021:19:03:14 +0000] "GET / HTTP/1.1" 403 555 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36" "-"

static-client-1  | 2021/12/01 19:03:14 [error] 31#31: *1 open() "/usr/share/nginx/html/favicon.ico" failed (13: Permission denied), client: 46.***.***.75, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "194.***.***.69:8000", referrer: "http://194.***.***69:8000/"


error 13: Permission denied
I can’t google how to solve and what is the problem

some other user inside the container with nginx is trying to read files from the host machine (volume)
and files with the rights of the host machine are mounted in the container - we have a conflict, am I right?
but how to win if correct

if you go inside the container in /usr/share/nginx/html
and there is my index.html
-rw------- 1 1000 1000 193 Dec 1 19:01 index.html

1000 is mine user (not root)
with
groups=1000(pankov),27(sudo),33(www-data),998(docker)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2021-12-01
@udjin123

Write User-Group Mapping

services:
    client:
        image: nginx:latest
        ports:
            - 8000:80
        user: "1000:1000"
        volumes:
            - ./src:/usr/share/nginx/html

A
Alexander Pankov, 2021-12-01
@PankovAlxndr

ran this on the host machine
chmod -R 755 src/
it was
drwx------ 2 pankov pankov 4096 Dec 1 20:00 src
became
drwxr-xr-x 2 pankov pankov 4096 Dec 1 20:00 src
and it worked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question