
本来是想 nginx 和 uwsgi 各自放一个 container. 通过 volume 映射 unix socket.但目前 uwsgi container 和本地的 nginx 都跑不通。。。同样的 uwsgi.ini 如果在本地直接运行则没有任何问题。
nginx 一直是 61 connection refused
[error] 12033#0: *1 connect() to unix:/tmp/uwsgi.sock failed (61: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/uwsgi.sock:", host: "localhost"
socket 在本地的映射(container volume 映射和本地直接运行 uwsgi 完全一样)
srw-rw-r-- 1 username wheel 0B Aug 23 21:43 uwsgi.sock
uwsgi.ini
[uwsgi] module = app:app strict = true master = true processes = 4 socket = /tmp/uwsgi.sock chmod-socket = 664 vacuum = true enable-threads = false single-interpreter = true need-app = true die-on-term = true max-requests = 1000 max-worker-lifetime = 3600 reload-on-rss = 2048 worker-reload-mercy = 60 app . py
from flask import Flask def create_app(): app = Flask(__name__) @app.route('/') def hello(): return '<h1>Hello There!</h1>' return app app = create_app() if __name__ == '__main__': app.run(host='0.0.0.0') Dockerfile
FROM python:3.7-slim RUN apt-get update && apt-get -y install python3-dev build-essential \ libpcre3 libpcre3-dev COPY . /src WORKDIR /src RUN pip install flask uwsgi ENTRYPOINT ["./run.sh"] run . sh
#!/usr/bin/env bash uwsgi --ini uwsgi.ini docker-compose
version: "3.5" services: uwsgi: build: app/ restart: on-failure volumes: - /tmp:/tmp/ webserver.conf
server { listen 80; server_name localhost; location / { include uwsgi_params; uwsgi_pass unix:/tmp/uwsgi.sock; } } 1 lhx2008 2019-08-24 10:00:04 +08:00 via Android 通过 volume 共享 socket ?这个想法一般人可想不到。 |
2 lhx2008 2019-08-24 10:02:08 +08:00 via Android 可惜 socket 应该只是记录了一些内存里面的信息,并不是用来传递数据的载体 |
3 lbfeng OP @lhx2008 原文在这:blog . myhro . info/2017/01/benchmarking-ip-and-unix-domain-sockets-for-real。 unix socket 比 tcp socket 更高效。 补充一下: 我刚才到 uwsgi 的 container 里看了下。 uwsgi.sock 在 container 里是这样的。 srw-rw-r-- 1 root root 0 Aug 24 02:00 uwsgi.sock 会不会和 user, group 有关?? |
4 julyclyde 2019-08-24 22:56:41 +08:00 这就是你们“啥都喜欢用 docker 解决”引发的问题 |