简体   繁体   English

Windows + VirtualBox + Ubuntu + Docker + Nginx 权限

[英]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 Windows 主机和 Ubuntu 来宾之间的共享文件夹具有以下权限: 777 in Windows 770 in Ubuntu

So... when I run a docker-compose like this:所以......当我像这样运行docker-compose时:

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:这是 Nginx 的 site.conf 文件:

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.容器中文件夹 /code 中的权限有 770 权限,并抛出 403 forbidden。 The permissions below are in Ubuntu (inside VBox) that are in the shared folder between Windows and Ubuntu (sf_compartida):以下权限在 Ubuntu(在 VBox 内)中,位于 Windows 和 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:以及 Web 容器内的权限:

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.我尝试使用其他文件夹(不是通过 VBox 共享的文件夹)并且它可以工作,而且如果我将权限从 777 更改为 770 它不再工作,所以一切都告诉我是权限导致了问题。

Please help... any idea?请帮助...有什么想法吗?

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但是我在群里理解了这个问题:vboxsf

I found the documentation我找到了文档

And create short script and mnt directory in home directory for current user并在当前用户的主目录中创建短脚本和mnt目录

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并运行此脚本: $ sudo ./mnt.sh

In mnt directory symlink was created on my shared directory Ubuntu1604Docker with right permissions current username:groupnamemnt目录中,在我的共享目录Ubuntu1604Docker上创建了符号链接,并具有当前用户名:组名的正确权限

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/

PS Sorry for my English PS对不起我的英语

I had the same problem using apache as webserver and solved doing the following:我在使用 apache 作为网络服务器时遇到了同样的问题,并解决了以下问题:

  • First, I added the vboxsf group into my container首先,我将 vboxsf 组添加到我的容器中
$ docker exec  addgroup --gid id_of_vboxsf_group
  • Then, I added the apache user (www-data, in my case) to the group然后,我将 apache 用户(在我的情况下为 www-data)添加到组中
$ docker exec  usermod -aG vboxsf www-data #(your user can be different)

I was not capable of changing the permissions, so I kind of mapped the same environment (user and group) from host to the docker container.我无法更改权限,因此我将相同的环境(用户和组)从主机映射到 docker 容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM