三行代码  ›  专栏  ›  技术社区  ›  Saturnian

PermissionError:[Errno 13]权限被拒绝:尽管在Dockerfile中授予了权限,但可能会出现什么问题?

  •  0
  • Saturnian  · 技术社区  · 1 月前

    application.log 归档 /app 文件夹我已通过Dockerfile授予该文件夹的写入权限,但我仍然看到该错误。在中创建文件时,我看不到它 /opt/docker

    这是我的想法 Dockerfile 看起来像:

    FROM nexus.company.com/docker-private/company-base:1.4.0
    
    LABEL team="Team"
    LABEL maintainer=team@company.com
    
    USER root
    
    # Create directory for logs - kubernetes logging sidecar reads logs from this location
    RUN mkdir -p /opt/docker/logs
    
    # Grant write permission
    RUN chown -R daemon:daemon /opt/docker
    
    # Install required packages tools
    RUN apt-get update -y && apt-get install -y python3-pip \
        # wget and zlib1g-dev to help with python3.6 installation
        &&  apt-get install -y wget && apt-get install -y zlib1g-dev \
        # The following line installs the ssl module required by pip3 to install requirements
        && apt-get install -y libssl-dev \
        # The following line installs the bz2 module required for pandas to install correctly
        && apt-get install -y libbz2-dev
    
    WORKDIR /opt
    
    # Download and install Python 3.6
    RUN wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz && tar -xvf Python-3.6.3.tgz
    RUN cd Python-3.6.3 && ./configure && make && make install
    
    # We copy just the requirements.txt first to leverage Docker cache
    COPY ./requirements.txt /app/requirements.txt
    
    # Permission for local application.log if running locally
    RUN chown -R daemon:daemon /app
    
    WORKDIR /app
    
    
    RUN pip3 install --upgrade pip && pip3 install -r requirements.txt
    
    # Copy all files to /app folder - we will run our application from here
    COPY . /app
    
    USER daemon
    
    # Run flask app with uwsgi
    ENTRYPOINT uwsgi --wsgi-file src/app.py --http-socket :9000 --callable app --ini app.ini
    
    

    Traceback (most recent call last):
      File "src/app.py", line 9, in <module>
        app = create_app()
      File "./src/__init__.py", line 41, in create_app
        setup_logging(app)
      File "./src/__init__.py", line 51, in setup_logging
        handler = logging.FileHandler(app.container.config.get("app.LOG_FILE"))
      File "/usr/local/lib/python3.6/logging/__init__.py", line 1030, in __init__
        StreamHandler.__init__(self, self._open())
      File "/usr/local/lib/python3.6/logging/__init__.py", line 1059, in _open
        return open(self.baseFilename, self.mode, encoding=self.encoding)
    PermissionError: [Errno 13] Permission denied: '/app/application.log'
    unable to load app 0 (mountpoint='') (callable not found or import error)
    *** no app loaded. GAME OVER ***
    

    我已授予此行的权限:

    # Permission for local application.log if running locally
    RUN chown -R daemon:daemon /app
    

    我应该做点别的吗?

    1 回复  |  直到 1 月前
        1
  •  1
  •   sytech    1 月前

    你需要跑步 chown 之后 --chown COPY

    COPY . /app
    RUN chown daemon:daemon -R /app
    

    --chown flag (仅限linux):

    COPY --chown=daemon:daemon . /app