【发布时间】:2021-01-01 22:07:07
【问题描述】:
我想在我的 VPS 上部署烧瓶应用程序。我想出了如何在没有 docker 的情况下轻松完成,但现在我将应用程序 docker 化并使用 docker-composer.yml 运行它。
services: │
myapp: │
build: ./myapp │
container_name: myapp │
restart: always │
environment: │
- APP_NAME = myapp │
expose: │
- 8081
所以我改变了我的 nginx 配置文件 来自
location / {
include uwsgi_params;
uwsgi_pass unix:/home/username/path/to/socket/mysocker.sock;
}
到
location / {
include uwsgi_params;
uwsgi_pass myapp:8081;
}
应用程序正在使用 docker composer 运行,但是当我使用 nginx -t 在 nginx 中测试正确的设置时,我收到了这条消息
nginx:在上游“myapp”中找不到[emerg]主机 /etc/nginx/sites-enabled/myapp:22 │nginx:配置文件/etc/nginx/nginx.conf测试失败
我很确定这意味着 nginx 无法找到在 docker 中运行的 myapp 并且无法与之通信,但我暴露了端口并且据我所知容器名称是主机名,因此它应该可以工作。 有谁知道如何让他们交流?我没有在互联网上找到任何不会对我不想要的 nginx 进行 docker 化的教程。
感谢任何帮助
编辑: 这是我的 Dockerfile
FROM python:3.8.5-buster
WORKDIR /app
ADD . /app
RUN apt-get update -y && apt-get -y install curl && apt-get install libsasl2$
RUN pip3 install mysqlclient
RUN pip3 install blinker
RUN pip3 install pyOpenSSL
RUN pip3 install uwsgi
RUN pip3 install -r requirements.txt
CMD ["uwsgi", "myproject.ini", "--enable-threads"]
UWSGI
[uwsgi]
wsgi-file=wsgi.py
callable=app
socket=8081
module = wsgi:app
master = true
processes = 1
chmod-socket = 666
vacuum = true
harakiri = 120
die-on-term = true
解决方案
- 将socket=8081改为socket=0.0.0.0:8081
- 改变nginx监听localhost:8081
- 将端口 8081:8081 添加到 docker-compose
【问题讨论】: