带Gunicorn的Docker:正在使用的连接:(';0.0.0.0';8000)

带Gunicorn的Docker:正在使用的连接:(';0.0.0.0';8000),docker,nginx,networking,gunicorn,wsgi,Docker,Nginx,Networking,Gunicorn,Wsgi,我正在尝试使用Gunicorn 我有一个Dockerfile文件,比如: FROM python:3.6.8-stretch RUN apt-get update && apt-get install -y --no-install-recommends nginx netcat postgresql-client COPY requirements.txt /opt/ RUN pip install -r /opt/requirements.txt RUN mkdir

我正在尝试使用
Gunicorn

我有一个
Dockerfile
文件,比如:

FROM python:3.6.8-stretch

RUN apt-get update && apt-get install -y --no-install-recommends nginx netcat postgresql-client

COPY requirements.txt /opt/

RUN pip install -r /opt/requirements.txt

RUN mkdir -p /run/nginx

RUN chmod +x /opt/my_turbo_app/deploy/docker/run-scripts/entrypoint.sh

ENTRYPOINT ["/opt/my_turbo_app/deploy/docker/run-scripts/entrypoint.sh"]
exec nginx &

gunicorn wsgi:application --bind 0.0.0.0:8000 --timeout 240 --workers 7 --log-file=- --log-level debug
一个
entrypoint.sh
类似:

FROM python:3.6.8-stretch

RUN apt-get update && apt-get install -y --no-install-recommends nginx netcat postgresql-client

COPY requirements.txt /opt/

RUN pip install -r /opt/requirements.txt

RUN mkdir -p /run/nginx

RUN chmod +x /opt/my_turbo_app/deploy/docker/run-scripts/entrypoint.sh

ENTRYPOINT ["/opt/my_turbo_app/deploy/docker/run-scripts/entrypoint.sh"]
exec nginx &

gunicorn wsgi:application --bind 0.0.0.0:8000 --timeout 240 --workers 7 --log-file=- --log-level debug
以及一个
requirements.txt
,它具有:

gevent==20.5.0
gunicorn==20.0.4
django==2.2.6
djangorestframework==3.10.3
我构建了
Dockerfile
,没有任何错误:

$ docker build -t my-turbo-app:latest
然后我用以下方法运行它:

$ docker run --rm -p 6379:6379 -d --name redis redis
$ docker run --rm -p 5432:5432 -d -e POSTGRES_HOST_AUTH_METHOD=trust --name postgres postgres
$ docker exec -it postgres psql -U postgres -h 127.0.0.1 -c 'CREATE DATABASE turbo_db;'
$ docker run -d --name my-turbo-app --link postgres:localhost --link redis:localhost -p 8000:8000 my-turbo-app:latest
容器
my turbo app
旋转一秒钟,然后崩溃

运行<代码>docker logs my turbo app显示:

+ gunicorn wsgi:application --bind 0.0.0.0:8000 --timeout 240 --workers 7 -k gevent --log-file=- --log-level debug
+ exec nginx
[2020-05-08 04:17:54 +0000] [8] [DEBUG] Current configuration:
  config: None
  bind: ['0.0.0.0:8000']
  backlog: 2048
  workers: 7
  worker_class: gevent
  threads: 1
  worker_connections: 1000
  max_requests: 0
  max_requests_jitter: 0
  timeout: 240
  graceful_timeout: 30
  keepalive: 2
  limit_request_line: 4094
  limit_request_fields: 100
  limit_request_field_size: 8190
  reload: False
  reload_engine: auto
  reload_extra_files: []
  spew: False
  check_config: False
  preload_app: False
  sendfile: None
  reuse_port: False
  chdir: /opt/my_turbo_app
  daemon: False
  raw_env: []
  pidfile: None
  worker_tmp_dir: None
  user: 0
  group: 0
  umask: 0
  initgroups: False
  tmp_upload_dir: None
  secure_scheme_headers: {'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-PROTO': 'https', 'X-FORWARDED-SSL': 'on'}
  forwarded_allow_ips: ['127.0.0.1']
  accesslog: None
  disable_redirect_access_to_syslog: False
  access_log_format: %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
  errorlog: -
  loglevel: debug
  capture_output: False
  logger_class: gunicorn.glogging.Logger
  logconfig: None
  logconfig_dict: {}
  syslog_addr: udp://localhost:514
  syslog: False
  syslog_prefix: None
  syslog_facility: user
  enable_stdio_inheritance: False
  statsd_host: None
  dogstatsd_tags: 
  statsd_prefix: 
  proc_name: None
  default_proc_name: wsgi:application
  pythonpath: None
  paste: None
  on_starting: <function OnStarting.on_starting at 0x7fc906cecae8>
  on_reload: <function OnReload.on_reload at 0x7fc906cecbf8>
  when_ready: <function WhenReady.when_ready at 0x7fc906cecd08>
  pre_fork: <function Prefork.pre_fork at 0x7fc906cece18>
  post_fork: <function Postfork.post_fork at 0x7fc906cecf28>
  post_worker_init: <function PostWorkerInit.post_worker_init at 0x7fc906d050d0>
  worker_int: <function WorkerInt.worker_int at 0x7fc906d051e0>
  worker_abort: <function WorkerAbort.worker_abort at 0x7fc906d052f0>
  pre_exec: <function PreExec.pre_exec at 0x7fc906d05400>
  pre_request: <function PreRequest.pre_request at 0x7fc906d05510>
  post_request: <function PostRequest.post_request at 0x7fc906d05598>
  child_exit: <function ChildExit.child_exit at 0x7fc906d056a8>
  worker_exit: <function WorkerExit.worker_exit at 0x7fc906d057b8>
  nworkers_changed: <function NumWorkersChanged.nworkers_changed at 0x7fc906d058c8>
  on_exit: <function OnExit.on_exit at 0x7fc906d059d8>
  proxy_protocol: False
  proxy_allow_ips: ['127.0.0.1']
  keyfile: None
  certfile: None
  ssl_version: 2
  cert_reqs: 0
  ca_certs: None
  suppress_ragged_eofs: True
  do_handshake_on_connect: False
  ciphers: None
  raw_paste_global_conf: []
  strip_header_spaces: False
[2020-05-08 04:17:54 +0000] [8] [INFO] Starting gunicorn 20.0.4
[2020-05-08 04:17:54 +0000] [8] [ERROR] Connection in use: ('0.0.0.0', 8000)
[2020-05-08 04:17:54 +0000] [8] [DEBUG] connection to ('0.0.0.0', 8000) failed: [Errno 98] Address already in use
[2020-05-08 04:17:54 +0000] [8] [ERROR] Retrying in 1 second.
[2020-05-08 04:17:55 +0000] [8] [ERROR] Connection in use: ('0.0.0.0', 8000)
[2020-05-08 04:17:55 +0000] [8] [DEBUG] connection to ('0.0.0.0', 8000) failed: [Errno 98] Address already in use
[2020-05-08 04:17:55 +0000] [8] [ERROR] Retrying in 1 second.
[2020-05-08 04:17:56 +0000] [8] [ERROR] Connection in use: ('0.0.0.0', 8000)
[2020-05-08 04:17:56 +0000] [8] [DEBUG] connection to ('0.0.0.0', 8000) failed: [Errno 98] Address already in use
[2020-05-08 04:17:56 +0000] [8] [ERROR] Retrying in 1 second.
[2020-05-08 04:17:57 +0000] [8] [ERROR] Connection in use: ('0.0.0.0', 8000)
[2020-05-08 04:17:57 +0000] [8] [DEBUG] connection to ('0.0.0.0', 8000) failed: [Errno 98] Address already in use
[2020-05-08 04:17:57 +0000] [8] [ERROR] Retrying in 1 second.
[2020-05-08 04:17:58 +0000] [8] [ERROR] Connection in use: ('0.0.0.0', 8000)
[2020-05-08 04:17:58 +0000] [8] [DEBUG] connection to ('0.0.0.0', 8000) failed: [Errno 98] Address already in use
[2020-05-08 04:17:58 +0000] [8] [ERROR] Retrying in 1 second.
[2020-05-08 04:17:59 +0000] [8] [ERROR] Can't connect to ('0.0.0.0', 8000)
+gunicorn wsgi:application--bind 0.0.0.0:8000--timeout 240--workers 7-k gevent--log file=--log-level debug
+执行nginx
[2020-05-08 04:17:54+0000][8][调试]当前配置:
配置:无
绑定:['0.0.0.0:8000']
积压:2048
工人:7人
工人类别:gevent
线程:1
工人人数:1000
最大请求数:0
最大请求抖动:0
超时:240
超时时间:30
保持活力:2
限制请求行:4094
限制请求字段:100
限制请求字段大小:8190
重新加载:False
重新加载引擎:自动
重新加载额外文件:[]
喷:错
检查配置:False
预加载应用程序:False
发送文件:无
重用端口:False
chdir:/opt/my\u turbo\u应用程序
守护进程:False
原始环境:[]
pidfile:无
工人\u tmp\u主管:无
用户:0
组别:0
乌马斯克:0
初始化组:False
tmp_上传_目录:无
安全方案标题:{'X-FORWARDED-PROTOCOL':'ssl','X-FORWARDED-PROTO':'https','X-FORWARDED-ssl':'on'}
转发的允许IP:['127.0.0.1']
访问日志:无
禁用\u重定向\u访问\u到\u系统日志:False
访问日志格式:%(h)s%(l)s%(u)s%(t)s“%(r)s”%(s)s%(b)s“%(f)s”%(a)s”
错误日志:-
日志级别:调试
捕获输出:False
记录器_类:gunicorn.glogg.logger
logconfig:None
logconfig_dict:{}
系统日志地址:udp://localhost:514
syslog:False
syslog\u前缀:无
syslog_设备:用户
启用_stdio_继承:False
statsd_主机:无
dogstatsd_标签:
statsd_前缀:
程序名称:无
默认进程名称:wsgi:application
蟒蛇:没有
粘贴:无
启动时:
重新加载时:
准备好后:
预制叉:
邮政叉子:
后期工作人员初始化:
劳工处:
工人中止:
预执行:
预请求:
后请求:
儿童出口:
工人出口:
nworkers_已更改:
退出时:
代理协议:False
代理允许IP:['127.0.0.1']
密钥文件:无
证书文件:无
ssl_版本:2
证书要求:0
证书:无
抑制不规则的EOF:正确
连接时是否握手:错误
密码:无
原始粘贴全局配置:[]
条带标题空格:False
[2020-05-08 04:17:54+0000][8][INFO]启动gunicorn 20.0.4
[2020-05-08 04:17:54+0000][8][错误]正在使用的连接:('0.0.0.0',8000)
[2020-05-08 04:17:54+0000][8][DEBUG]到('0.0.0',8000)的连接失败:[Errno 98]地址已在使用中
[2020-05-08 04:17:54+0000][8][错误]1秒后重试。
[2020-05-08 04:17:55+0000][8][错误]正在使用的连接:('0.0.0.0',8000)
[2020-05-08 04:17:55+0000][8][DEBUG]到('0.0.0',8000)的连接失败:[Errno 98]地址已在使用中
[2020-05-08 04:17:55+0000][8][错误]1秒后重试。
[2020-05-08 04:17:56+0000][8][错误]正在使用的连接:('0.0.0.0',8000)
[2020-05-08 04:17:56+0000][8][DEBUG]到('0.0.0',8000)的连接失败:[Errno 98]地址已在使用中
[2020-05-08 04:17:56+0000][8][错误]1秒后重试。
[2020-05-08 04:17:57+0000][8][错误]正在使用的连接:('0.0.0.0',8000)
[2020-05-08 04:17:57+0000][8][DEBUG]到('0.0.0',8000)的连接失败:[Errno 98]地址已在使用中
[2020-05-08 04:17:57+0000][8][错误]1秒后重试。
[2020-05-08 04:17:58+0000][8][错误]正在使用的连接:('0.0.0.0',8000)
[2020-05-08 04:17:58+0000][8][DEBUG]到('0.0.0',8000)的连接失败:[Errno 98]地址已在使用中
[2020-05-08 04:17:58+0000][8][错误]1秒后重试。
[2020-05-08 04:17:59+0000][8][错误]无法连接到('0.0.0.0',8000)

我尝试绑定不同的端口,但似乎不起作用。如何让gunicorn与docker一起运行?

nginx和gunicorn进程是否都设置为侦听端口8000?您可能应该在单独的容器中运行nginx代理。nginx和gunicorn进程是否都设置为侦听端口8000?您可能应该在单独的容器中运行nginx代理。