Gunicorn 无法连接到 Alpine 上的 sock 文件
Gunicorn not able to connect to sock file on Alpine
有很多关于这个主题的问题,但 none 对我有帮助。
我正在尝试将 Gunicorn 连接到 /tmp/gunicorn.sock
,但我一直在连接 operation not permitted
。我的 gunicorn.conf.py
看起来像:
import multiprocessing
# bind = '127.0.0.1:5000'
bind = 'unix:/tmp/gunicorn.sock'
backlog = 2048
preload_app = True
max_requests = 2048
max_requests_jitter = 128
workers = multiprocessing.cpu_count() * 2 + 1
worker_connections = 1000
timeout = 60
keepalive = 2
errorlog = '-'
loglevel = 'debug'
accesslog = '-'
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
def when_ready(server):
open('/tmp/app-initialized', 'w').close()
我的日志是:
[2018-08-03 02:34:40 +0000] [116] [INFO] Starting gunicorn 19.9.0
[2018-08-03 02:34:40 +0000] [116] [DEBUG] connection to /tmp/gunicorn.sock failed: [Errno 1] Operation not permitted
[2018-08-03 02:34:40 +0000] [116] [ERROR] Retrying in 1 second.
[2018-08-03 02:34:41 +0000] [116] [DEBUG] connection to /tmp/gunicorn.sock failed: [Errno 1] Operation not permitted
[2018-08-03 02:34:41 +0000] [116] [ERROR] Retrying in 1 second.
[2018-08-03 02:34:42 +0000] [116] [DEBUG] connection to /tmp/gunicorn.sock failed: [Errno 1] Operation not permitted
[2018-08-03 02:34:42 +0000] [116] [ERROR] Retrying in 1 second.
[2018-08-03 02:34:43 +0000] [116] [DEBUG] connection to /tmp/gunicorn.sock failed: [Errno 1] Operation not permitted
[2018-08-03 02:34:43 +0000] [116] [ERROR] Retrying in 1 second.
[2018-08-03 02:34:44 +0000] [116] [DEBUG] connection to /tmp/gunicorn.sock failed: [Errno 1] Operation not permitted
[2018-08-03 02:34:44 +0000] [116] [ERROR] Retrying in 1 second.
[2018-08-03 02:34:45 +0000] [116] [ERROR] Can't connect to /tmp/gunicorn.sock
这看起来像是用户权限错误,但这应该不是问题,因为 gunicorn
是 运行ning 作为 root
/opt/app # ps aux | grep gunicorn
123 root 0:00 grep gunicorn
我还尝试创建一个用户和一个组作为 addgroup -S appgroup && adduser -S appuser -G appgroup
并通过执行 chown appuser:appgroup /tmp/
更改 /tmp/
文件夹的权限(因为未创建 gunicorn.sock
文件).
OS 中的内容作为 root
执行,但我仍然收到此错误。我应该如何通过 gunicorn.sock
文件使其 运行 成为可能?
更新
My `Dockerfile`:
FROM python:3.6.6-alpine3.8
# Update, install the required packages and clean downloaded package
RUN apk update && \
apk upgrade && \
apk add postgresql-dev nginx supervisor && \
rm -rf /var/cache/apk/*
# Copy files
...
# setup all the configfiles
COPY config/nginx.conf /etc/nginx/nginx.conf
COPY config/nginx-app.conf /etc/nginx/sites-available/default
COPY config/supervisor-app.conf /etc/supervisor/conf.d/
# Install requirements
...
EXPOSE 8113
CMD ["supervisord", "-n", "-c", "/opt/app/config/supervisor-app.conf"]
感谢 https://github.com/benoitc/gunicorn/issues/1849 的人。
为了即时创建套接字,您可能必须将它们放在 /run/
中,即 bind='unix:/run/gunicron.sock'
然后您可以使用 Nginx 作为反向代理并通过给定的套接字文件提供服务。
但是为什么/run/
?
Run-time variable data: Information about the running system since
last boot, e.g., currently logged-in users and running daemons. Files
under this directory must be either removed or truncated at the
beginning of the boot process; but this is not necessary on systems
that provide this directory as a temporary filesystem (tmpfs).
有关详细信息,请参阅 https://unix.stackexchange.com/questions/13972/what-is-this-new-run-filesystem。
有很多关于这个主题的问题,但 none 对我有帮助。
我正在尝试将 Gunicorn 连接到 /tmp/gunicorn.sock
,但我一直在连接 operation not permitted
。我的 gunicorn.conf.py
看起来像:
import multiprocessing
# bind = '127.0.0.1:5000'
bind = 'unix:/tmp/gunicorn.sock'
backlog = 2048
preload_app = True
max_requests = 2048
max_requests_jitter = 128
workers = multiprocessing.cpu_count() * 2 + 1
worker_connections = 1000
timeout = 60
keepalive = 2
errorlog = '-'
loglevel = 'debug'
accesslog = '-'
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
def when_ready(server):
open('/tmp/app-initialized', 'w').close()
我的日志是:
[2018-08-03 02:34:40 +0000] [116] [INFO] Starting gunicorn 19.9.0
[2018-08-03 02:34:40 +0000] [116] [DEBUG] connection to /tmp/gunicorn.sock failed: [Errno 1] Operation not permitted
[2018-08-03 02:34:40 +0000] [116] [ERROR] Retrying in 1 second.
[2018-08-03 02:34:41 +0000] [116] [DEBUG] connection to /tmp/gunicorn.sock failed: [Errno 1] Operation not permitted
[2018-08-03 02:34:41 +0000] [116] [ERROR] Retrying in 1 second.
[2018-08-03 02:34:42 +0000] [116] [DEBUG] connection to /tmp/gunicorn.sock failed: [Errno 1] Operation not permitted
[2018-08-03 02:34:42 +0000] [116] [ERROR] Retrying in 1 second.
[2018-08-03 02:34:43 +0000] [116] [DEBUG] connection to /tmp/gunicorn.sock failed: [Errno 1] Operation not permitted
[2018-08-03 02:34:43 +0000] [116] [ERROR] Retrying in 1 second.
[2018-08-03 02:34:44 +0000] [116] [DEBUG] connection to /tmp/gunicorn.sock failed: [Errno 1] Operation not permitted
[2018-08-03 02:34:44 +0000] [116] [ERROR] Retrying in 1 second.
[2018-08-03 02:34:45 +0000] [116] [ERROR] Can't connect to /tmp/gunicorn.sock
这看起来像是用户权限错误,但这应该不是问题,因为 gunicorn
是 运行ning 作为 root
/opt/app # ps aux | grep gunicorn
123 root 0:00 grep gunicorn
我还尝试创建一个用户和一个组作为 addgroup -S appgroup && adduser -S appuser -G appgroup
并通过执行 chown appuser:appgroup /tmp/
更改 /tmp/
文件夹的权限(因为未创建 gunicorn.sock
文件).
OS 中的内容作为 root
执行,但我仍然收到此错误。我应该如何通过 gunicorn.sock
文件使其 运行 成为可能?
更新
My `Dockerfile`:
FROM python:3.6.6-alpine3.8
# Update, install the required packages and clean downloaded package
RUN apk update && \
apk upgrade && \
apk add postgresql-dev nginx supervisor && \
rm -rf /var/cache/apk/*
# Copy files
...
# setup all the configfiles
COPY config/nginx.conf /etc/nginx/nginx.conf
COPY config/nginx-app.conf /etc/nginx/sites-available/default
COPY config/supervisor-app.conf /etc/supervisor/conf.d/
# Install requirements
...
EXPOSE 8113
CMD ["supervisord", "-n", "-c", "/opt/app/config/supervisor-app.conf"]
感谢 https://github.com/benoitc/gunicorn/issues/1849 的人。
为了即时创建套接字,您可能必须将它们放在 /run/
中,即 bind='unix:/run/gunicron.sock'
然后您可以使用 Nginx 作为反向代理并通过给定的套接字文件提供服务。
但是为什么/run/
?
Run-time variable data: Information about the running system since last boot, e.g., currently logged-in users and running daemons. Files under this directory must be either removed or truncated at the beginning of the boot process; but this is not necessary on systems that provide this directory as a temporary filesystem (tmpfs).
有关详细信息,请参阅 https://unix.stackexchange.com/questions/13972/what-is-this-new-run-filesystem。