2016-12-01 110 views
1

我正在docker-compose彙集的Django與一些其他的服務,以下配置:泊塢窗的用戶權限被拒絕在容器訪問文件夾

Dockerfile

FROM ubuntu:16.10 
FROM python:3.5.0 

ENV EXTRACTOR_SRC=. 
ENV EXTRACTOR_SRVHOME=/srv 
ENV EXTRACTOR_SRVPROJ=/srv/extractor_django 

#Install package dependencies 
RUN apt-get update && apt-get -y upgrade 
RUN apt-get install -y python python-pip virtualenvwrapper 

# Create application subdirectories 
WORKDIR $EXTRACTOR_SRVHOME 
RUN mkdir media static logs 
VOLUME ["$EXTRACTOR_SRVHOME/media/", "$EXTRACTOR_SRVHOME/logs/"] 

# Copy application source code to SRCDIR 
COPY $EXTRACTOR_SRC $EXTRACTOR_SRVPROJ 

# Install Python dependencies 
RUN pip install -r $EXTRACTOR_SRVPROJ/requirements.txt 

# create user 
RUN adduser --disabled-password --gecos '' dockeruser 

(相關)泊塢窗-compose.yml

version: '2' 

services: 

    # Django web server 
    web: 
    build: 
     context: . 
     dockerfile: Dockerfile 
    hostname: web 
    command: /srv/www/run_web.sh 
    volumes: 
      - .:/srv/www 
    ports: 
     - "8000:8000" 

run_web.sh

#!/bin/bash 
set -o verbose 

sleep 15 
cd /srv/extractor_django 

su -m dockeruser -c "python manage.py makemigrations" 
su -m dockeruser -c "python manage.py migrate" 
su -m dockeruser -c "python manage.py collectstatic --noinput" 

# Start Gunicorn processes 
echo Starting Gunicorn. 

su -m dockeruser -c "gunicorn extractorService.wsgi:application \ 
    --name extractor_django \ 
    --bind 0.0.0.0:8000 \ 
    --workers 10 \ 
    --log-level=info" 

運行期間的蟒蛇要求(spacy)試圖向存儲和訪問文件的文件夾的限制導致錯誤:

PermissionError: [Errno 13] Permission denied:  
'/usr/local/lib/python3.5/site-packages/spacy/data' 

有沒有一種方法可以讓我給dockeruser足夠的權限,這將工作。或者,用virtualenv運行這個問題似乎更容易理解,因爲問題似乎是訪問系統範圍的python文件夾?

回答

0

你可以用Docker以外的方式解決這個問題。通過該文件夾/結構爲該用戶提供適當的權限,或者如您所說可以使用virtualenv。

0

您是否嘗試使用privileged選項向容器賦予擴展權限?

version: '2' 

services: 

    # Django web server 
    web: 
    build: 
     privileged: true 
     context: . 
     dockerfile: Dockerfile 
    hostname: web 
    command: /srv/www/run_web.sh 
    volumes: 
      - .:/srv/www 
    ports: 
     - "8000:8000"