API&x27;在使用docker和uwsgi/nginx部署的flask应用程序中,s不会受到攻击

API&x27;在使用docker和uwsgi/nginx部署的flask应用程序中,s不会受到攻击,docker,nginx,flask,dockerfile,uwsgi,Docker,Nginx,Flask,Dockerfile,Uwsgi,我可以使用下面的docker文件创建docker映像 FROM python:3.6 # FROM tiangolo/uwsgi-nginx-flask:python3.6 RUN mkdir /trell-ds-framework WORKDIR /trell-ds-framework ADD . /trell-ds-framework/ RUN python setup.py bdist_wheel USER root RUN apt-get -y update RUN apt-get in

我可以使用下面的docker文件创建docker映像

FROM python:3.6
# FROM tiangolo/uwsgi-nginx-flask:python3.6
RUN mkdir /trell-ds-framework
WORKDIR /trell-ds-framework
ADD . /trell-ds-framework/
RUN python setup.py bdist_wheel
USER root
RUN apt-get -y update
RUN apt-get install -y --no-install-recommends libatlas-base-dev gfortran nginx supervisor
RUN pip3 install uwsgi
RUN  apt-get install -y libsndfile1-dev
RUN apt-get install -y ca-certificates
RUN apt-get update && apt-get -y install cron
RUN pip install -r requirements.txt
RUN python -c "import nltk;nltk.download('stopwords')"
# Replace with our own nginx.conf
COPY nginx.conf /etc/nginx/conf.d/
EXPOSE 5000
# CMD ["python", "/trell-ds-framework/application.py"]
CMD ["uwsgi", "ds_backend.ini"]
使用此命令生成图像 docker构建-t ds_后端

以下是我的
ds\u backend.ini
文件和
nginx.file
,与
Dockerfile
位于同一项目目录中,供您参考

ds_backend.ini文件

[uwsgi]
module = wsgi:app
processes = 20
socket = ds_backend.sock
vacuum = true
chmod-socket = 660
die-on-term = true
socket-timeout = 300
http-timeout = 300
ignore-sigpipe=true
ignore-write-errors=true
disable-write-exception=true
nginx.conf文件

server {
    listen 80;
    location / {
        include uwsgi_params;
        uwsgi_pass localhost:5000;
    }

}
使用下面的命令运行图像
docker运行-p 5001:5000 ds_后端

并获得以下输出

[nltk_data] Downloading package stopwords to /root/nltk_data...
[nltk_data]   Package stopwords is already up-to-date!
WSGI app 0 (mountpoint='') ready in 27 seconds on interpreter 0x55b062460140 pid: 1 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (pid: 1, cores: 1)
spawned uWSGI worker 2 (pid: 195, cores: 1)
spawned uWSGI worker 3 (pid: 196, cores: 1)
spawned uWSGI worker 4 (pid: 197, cores: 1)
spawned uWSGI worker 5 (pid: 198, cores: 1)
spawned uWSGI worker 6 (pid: 199, cores: 1)
spawned uWSGI worker 7 (pid: 200, cores: 1)
spawned uWSGI worker 8 (pid: 201, cores: 1)
spawned uWSGI worker 9 (pid: 202, cores: 1)
spawned uWSGI worker 10 (pid: 203, cores: 1)
spawned uWSGI worker 11 (pid: 204, cores: 1)
spawned uWSGI worker 12 (pid: 205, cores: 1)
spawned uWSGI worker 13 (pid: 206, cores: 1)
spawned uWSGI worker 14 (pid: 207, cores: 1)
spawned uWSGI worker 15 (pid: 208, cores: 1)
spawned uWSGI worker 16 (pid: 209, cores: 1)
spawned uWSGI worker 17 (pid: 210, cores: 1)
spawned uWSGI worker 18 (pid: 211, cores: 1)
spawned uWSGI worker 19 (pid: 212, cores: 1)
spawned uWSGI worker 20 (pid: 213, cores: 1)
但是,当我试图使用ip:port/end_point(错误:connect-econnrefuseip:port)点击来自postman的API调用时,API并没有被点击,也看不到上述部署日志中的任何日志

有人能帮我吗?我对使用nginx/uwsgi部署flask应用程序的Docker完全是新手

任何线索都是高度赞赏的。谢谢


PS:我已在虚拟机中启用5000和5001端口。

localhost
在Docker中通常表示“此容器”,因此您已将Nginx配置为转发到Nginx容器中的端口5000。即使你没有使用Docker Compose,也是很好的背景阅读;您必须手动
docker network创建一个网络来允许容器之间的连接。嘿,谢谢您的回答。事实上,我只需要建造一个集装箱,可以只装一个集装箱吗?我尝试过这种配置,把所有的东西放在一个容器中,但遇到了一些问题。我在那里详细提到过。如果可能的话,你能循环一下吗?最好的做法是每个容器一个过程。这还允许您使用预构建的数据库映像,这将为您节省一些麻烦。数据库、Flask应用程序和Nginx反向代理的三个容器应该是非常常规的配置。
localhost
在Docker中通常表示“此容器”,因此您已将Nginx配置为转发到Nginx容器中的端口5000。即使你没有使用Docker Compose,也是很好的背景阅读;您必须手动
docker network创建一个网络来允许容器之间的连接。嘿,谢谢您的回答。事实上,我只需要建造一个集装箱,可以只装一个集装箱吗?我尝试过这种配置,把所有的东西放在一个容器中,但遇到了一些问题。我在那里详细提到过。如果可能的话,你能循环一下吗?最好的做法是每个容器一个过程。这还允许您使用预构建的数据库映像,这将为您节省一些麻烦。数据库、Flask应用程序和Nginx反向代理的三个容器应该是非常常规的配置。