我有一個 Flask Python 應用程式,它application.log在/app檔案夾中創建一個檔案。我已經通過我的 Dockerfile 授予了對該檔案夾的寫權限,但是我仍然看到那個錯誤。在該/opt/docker位置創建檔案時,我看不到它。可能是什么問題?
這是我的Dockerfile樣子:
FROM nexus.company.com/docker-private/company-base:1.4.0
LABEL team="Team"
LABEL [email protected]
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
我應該做點別的嗎?
uj5u.com熱心網友回復:
您需要chown 在將檔案復制到該目錄后運行。或者,您可以將--chown標志用于COPY. 否則,它們將被復制為 root 用戶所擁有,從而導致權限錯誤。
COPY . /app
RUN chown daemon:daemon -R /app
或使用--chown標志(僅限 linux):
COPY --chown=daemon:daemon . /app
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/370496.html
