Docker Compose:Django、uWSGI、无代理的NGINX(不同容器)
我的docker compose.yaml是Docker Compose:Django、uWSGI、无代理的NGINX(不同容器),docker,nginx,uwsgi,Docker,Nginx,Uwsgi,我的docker compose.yaml是 version: '3' services: nginx: restart: always build: ./nginx/ depends_on: - web ports: - "8000:8000" network_mode: "host" # Connection between containers web: build: . image: app-
version: '3'
services:
nginx:
restart: always
build: ./nginx/
depends_on:
- web
ports:
- "8000:8000"
network_mode: "host" # Connection between containers
web:
build: .
image: app-image
ports:
- "80:80"
volumes:
- .:/app-name
command: uwsgi /app-path/web/app.ini
NGINX conf文件是
upstream web {
server 0.0.0.0:80;
}
server {
listen 8000;
server_name web;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias "/app-static/";
}
location / {
proxy_pass http://web;
}
}
所以基本上我把Django和uWSGI放在一个容器“web”中,而NGINX放在容器“NGINX”中。我通过代理使用NGINX链接了两者,两者都运行良好。(我不知何故需要“网络模式:”主机“,如果没有它就无法工作) 因为它们是不同的容器,所以我不能使用.sock文件(除非我使用一些卷攻击来共享.sock文件,这不好!) 尽管这是可行的,但我还是被要求避免通过代理使用NGINX,那么有没有其他方法来连接这两者呢 搜索并没有给我其他的选择。我试过了