我有一个Django应用程序,我想在docker中部署它,但我得到了错误PermissionError: [Errno 13] Permission denied: '/var/log/gunicorn.error.log'
。我不知道问题出在哪里了。有人能帮我吗?
我的码头文件:
# BUILDER #
###########
# pull official base image
FROM python:3.9.6-slim as builder
# set work directory
WORKDIR /app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install system dependencies
RUN apt-get update
&& apt-get install -y build-essential python3-dev python2.7-dev
libldap2-dev libsasl2-dev libssl-dev ldap-utils tox
lcov valgrind
&& apt-get -y install gcc
&& apt install -y netcat
# install psycopg2 dependencies
RUN apt-get install -y postgresql-server-dev-all musl-dev
# lint
RUN pip install --upgrade pip
COPY . .
# install python dependencies
COPY requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
# pull official base image
FROM python:3.9.6-slim
RUN apt-get update && apt install -y netcat
# create directory for the app user
RUN mkdir -p /home/app
# create the app user
RUN addgroup --system --disabled-password app && adduser --system --group --disabled-password app
# RUN addgroup --system app && adduser --system --group app
# RUN adduser --disabled-password --gecos '' app
# create the appropriate directories
ENV APP_HOME=/home/app
WORKDIR $APP_HOME
# install dependencies
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /app/requirements.txt .
RUN pip install --upgrade pip
RUN pip install --no-cache /wheels/*
# copy entrypoint.sh
COPY ./entrypoint.sh $APP_HOME
RUN sed -i 's/r$//g' $APP_HOME/entrypoint.sh
RUN chmod +x $APP_HOME/entrypoint.sh
# copy project
COPY . $APP_HOME
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# change to the app user
USER app
# run entrypoint.sh
ENTRYPOINT ["/home/app/entrypoint.sh"]
和入口点文件:
#!/bin/sh
if [ "$DATABASE" = "postgres" ]
then
echo "Waiting for postgres..."
while ! nc -z $SQL_HOST $SQL_PORT; do
sleep 0.1
done
echo "postgres database has initialized successfully"
fi
echo"ls"
ls
# echo "Running Migrations"
# python manage.py migrate --no-input
# python manage.py collectstatic --no-inp
# Start server
echo "who am i"
whoami
echo "Server Started"
gunicorn -c gunicorn.conf.py culture_crawler.wsgi:application
# python manage.py runserver 0.0.0.0:8000
exec "$@"
gunicorn.config.py文件
# gunicorn.conf.py
# Non logging stuff
bind = "0.0.0.0:8000"
workers = 3
# Access log - records incoming HTTP requests
accesslog = "/var/log/gunicorn.access.log"
# Error log - records Gunicorn server goings-on
errorlog = "/var/log/gunicorn.error.log"
# Whether to send Django output to the error log
capture_output = True
# How verbose the Gunicorn error logs should be
loglevel = "info"
整个错误:
web_1 | Server Started
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/bin/gunicorn", line 8, in <module>
web_1 | sys.exit(run())
web_1 | File "/usr/local/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
web_1 | WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
web_1 | File "/usr/local/lib/python3.9/site-packages/gunicorn/app/base.py", line 228, in run
web_1 | super().run()
web_1 | File "/usr/local/lib/python3.9/site-packages/gunicorn/app/base.py", line 72, in run
web_1 | Arbiter(self).run()
web_1 | File "/usr/local/lib/python3.9/site-packages/gunicorn/arbiter.py", line 58, in __init__
web_1 | self.setup(app)
web_1 | File "/usr/local/lib/python3.9/site-packages/gunicorn/arbiter.py", line 93, in setup
web_1 | self.log = self.cfg.logger_class(app.cfg)
web_1 | File "/usr/local/lib/python3.9/site-packages/gunicorn/glogging.py", line 195, in __init__
web_1 | self.setup(cfg)
web_1 | File "/usr/local/lib/python3.9/site-packages/gunicorn/glogging.py", line 207, in setup
web_1 | self.logfile = open(cfg.errorlog, 'a+')
web_1 | PermissionError: [Errno 13] Permission denied: '/var/log/gunicorn.error.log'
提前感谢
授予执行文件的访问权限:
sudo chmod 666 /var/log/gunicorn.error.log
或者使用root权限运行命令:
sudo ./your_entrypoint _file