nginx - Docker 容器遇到套接字问题(单独的 Flask + Nginx 容器)

标签 nginx docker uwsgi docker-compose

在运行 docker-compose build && docker-compose up 并尝试访问我的索引页面后,我的多容器 Docker 设置遇到以下错误:

[crit] 8#8: *1 connect() to unix:/tmp/uwsgi.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.99.1, server: localhost, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/uwsgi.sock:", host: "192.168.99.100"

这是我的 docker-compose.yml:
web:
  restart: always
  build: ./web-app
  expose:
    - "8000"
  command: /usr/local/bin/uwsgi --ini sample-uwsgi.ini

nginx:
  restart: always
  build: ./nginx/
  ports:
    - "80:80"
  links:
    - web:web

nginx/Dockerfile
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
ADD sample-nginx.conf /etc/nginx/conf.d/

nginx/sample-nginx.conf
server {

    listen 80;
    server_name localhost;
    charset utf-8;
    client_max_body_size 75M;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/uwsgi.sock;
    }
}

网络应用程序/Dockerfile
FROM ansible/ubuntu14.04-ansible:stable

WORKDIR /root
ADD application.py application.py
ADD requirements.txt requirements.txt
ADD sample-uwsgi.ini sample-uwsgi.ini

ADD ansible /srv/ansible
WORKDIR /srv/ansible

RUN ansible-playbook container-bootstrap.yml -c local

web-app/sample-uswgi.ini
[uwsgi]

module = application
callable = app

master = true
processes = 5

socket = /tmp/uwsgi.sock

chown-socket = www-data:www-data

vacuum = true
enable-threads=True
die-on-term = true

更新

根据@kryten 的建议,我将使用 TCP/IP

更新 nginx.conf:
server {

    listen 80;
    server_name localhost;
    charset utf-8;
    client_max_body_size 75M;

    location / {
        uwsgi_pass localhost:8000;
        include uwsgi_params;
    }
}

更新了 uwsgi.ini:
[uwsgi]

module = application
callable = app

master = true
processes = 5

socket = localhost:8000

chown-socket = www-data:www-data

vacuum = true
enable-threads=True
die-on-term = true

并且我现在追求以下错误:
[error] 8#8: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.99.1, server: localhost, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8000", host: "192.168.99.100"

最佳答案

webnginx是单独的容器,nginx 需要通过 TCP 连接到另一台计算机。 Linking the containers已经完成了大部分工作,您只需将上游指向 web:8000而不是本地主机。

关于nginx - Docker 容器遇到套接字问题(单独的 Flask + Nginx 容器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32384061/

相关文章:

python - uWSGI worker 卡住 : why

python - 第一个请求不会终止(无 FIN)uWSGI + nginx

ruby-on-rails - Nginx 乘客集成模式总是需要 Passengerfile.json 文件?

nginx - fastcgi-mono-server4 和 nginx 与 docker

docker - Docker CMD指令执行

docker - docker celery 和代码在不同的容器中

uwsgi - 如何使用 uWSGI 内部路由将 HTTP 重定向到 HTTPS?

php - Nginx - 提供没有扩展名的图像

nginx - Docker和Spring Boot:如何从URL隐藏端口?

python - Docker pip3未安装软件包