Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows + VirtualBox + Ubuntu + Docker + Nginx permissions

The shared folder between Windows host and Ubuntu guest has the following permissions: 777 in Windows 770 in Ubuntu

So... when I run a docker-compose like this:

version: '2'

services:
    web:
        image: nginx:latest
        ports:
            - "8080:80"
        volumes:
            - ./sf_compartida/codigo:/code
            - ./site.conf:/etc/nginx/conf.d/default.conf
        networks:
            - code-network
    php:
        image: php:fpm
        volumes:
            - ./sf_compartida/codigo:/code
        networks:
            - code-network

networks:
    code-network:
        driver: bridge

And this site.conf file for Nginx:

server {
    listen 80;
    index index.php index.html;
    server_name localhost;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /code;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

The permissions in the folder /code in the container has 770 permissions and it throws 403 forbidden. The permissions below are in Ubuntu (inside VBox) that are in the shared folder between Windows and Ubuntu (sf_compartida):

/home/ubuntu/geek/dockerised-php/sf_compartida/codigo
drwxrwx--- 1 root vboxsf    0 abr 11 20:27 ./
drwxrwx--- 1 root vboxsf 4096 abr 11 20:24 ../
-rwxrwx--- 1 root vboxsf    2 mar 27 17:42 adios.php*
-rwxrwx--- 1 root vboxsf    0 abr 11 20:07 fichero1.php*
-rwxrwx--- 1 root vboxsf   24 mar 27 17:40 hola.php*
-rwxrwx--- 1 root vboxsf   29 mar 25 23:56 index.php*

And the permissions inside the web container:

drwxrwx--- 1 root  119    0 Apr 11 18:27 .
drwxr-xr-x 1 root root 4096 Apr 11 19:00 ..
-rwxrwx--- 1 root  119    2 Mar 27 15:42 adios.php
-rwxrwx--- 1 root  119    0 Apr 11 18:07 fichero1.php
-rwxrwx--- 1 root  119   24 Mar 27 15:40 hola.php
-rwxrwx--- 1 root  119   29 Mar 25 21:56 index.php

I tried with other folder (not the shared one throught VBox) and it works, and also if I change the permissions from 777 to 770 it doesn't work anymore, so everything tells me the permissions are causing the issue.

Please help... any idea?

like image 509
jmunozco Avatar asked Apr 11 '18 19:04

jmunozco


1 Answers

I have some problem. And I tried to solve this problem but did not find anything.

But I understood that problem in the group: vboxsf

I found the documentation

And create short script and mnt directory in home directory for current user

sharename="Ubuntu1604Docker"
sudo mkdir /mnt/$sharename 
sudo chmod 777 /mnt/$sharename 
sudo mount -t vboxsf -o uid=1000,gid=1000 $sharename /mnt/$sharename 
ln -s /mnt/$sharename $HOME/mnt/$sharename

and run this script: $ sudo ./mnt.sh

In mnt directory symlink was created on my shared directory Ubuntu1604Docker with right permissions current username:groupname

script@ubuntu-16:~/mnt$ ll
total 8
drwxrwxr-x  2 script script 4096 Apr 29 19:45 ./
drwxr-xr-x 10 script script 4096 Apr 29 19:58 ../
lrwxrwxrwx  1 script script   21 Apr 29 19:45 Ubuntu1604Docker -> /mnt/Ubuntu1604Docker/

P.S. Sorry for my English

like image 150
Script Avatar answered Oct 13 '22 15:10

Script