在运行docker-compose build && docker-compose并尝试打开我的索引页后,我遇到了以下多错误:
[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的/采样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; } }
web应用程序/ 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应用程序/采样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
UPDATE
从@kryten的build议我将使用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"
它看起来像你的应用程序之一是试图通过Unix套接字,而不是通过TCP / IP连接。
这将不会在不同的容器中工作,因为一个容器中的文件系统(套接字所在的位置)不能在其他容器中访问。
解决方案是重新配置您的应用程序连接通过TCP / IP而不是一个Unix套接字。
通过将套接字所在的文件系统中的位置暴露给另一个容器来连接也许是可能的,但我从来没有试过这个&不知道它是否会工作。
由于web和nginx是独立的容器,因此nginx需要通过TCP连接到另一台计算机 。 链接容器已经完成了大部分工作,你只需要将上游指向web:8000而不是localhost。