我已经构建了一个Dockerfile
,如下所示:
FROM python:2-jessie
ENV DOCKER_MODE=1
EXPOSE 1818
# everything is copied to my_app like uwsgi.ini and app files
COPY . /my_app
WORKDIR /my_app
CMD ["uwsgi", "--ini", "uwsgi.ini"]
它就像一个魅力:
Sun Oct 29 15:17:34 2017 - uWSGI http bound on 127.0.0.1:1818 fd 4
Sun Oct 29 15:17:34 2017 - uwsgi socket 0 bound to TCP address 127.0.0.1:43183 (port auto-assigned) fd 3
Sun Oct 29 15:17:34 2017 - Python version: 2.7.14 (default, Oct 10 2017, 02:49:49) [GCC 4.9.2]
Sun Oct 29 15:17:34 2017 - Python main interpreter initialized at 0x1e347e0
Sun Oct 29 15:17:34 2017 - python threads support enabled
Sun Oct 29 15:17:34 2017 - your server socket listen backlog is limited to 100 connections
Sun Oct 29 15:17:34 2017 - your mercy for graceful operations on workers is 10 seconds
Sun Oct 29 15:17:34 2017 - mapped 1155328 bytes (1128 KB) for 50 cores
Sun Oct 29 15:17:35 2017 - WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x1e347e0 pid: 1 (default app)
Sun Oct 29 15:17:35 2017 - *** uWSGI is running in multiple interpreter mode ***
Sun Oct 29 15:17:35 2017 - spawned uWSGI master process (pid: 1)
Sun Oct 29 15:17:35 2017 - spawned uWSGI worker 1 (pid: 9, cores: 50)
Sun Oct 29 15:17:35 2017 - *** Stats server enabled on 127.0.0.1:11818 fd: 12 ***
Sun Oct 29 15:17:35 2017 - spawned uWSGI http 1 (pid: 10)
当我运行docker镜像并分配像33000
这样的端口时,它正在侦听该端口:
admin@server:~/application$ sudo netstat -nltp | grep 33000
tcp6 0 0 :::33000 :::* LISTEN 10922/docker-proxy
似乎没有错!现在我的nginx代理在端口80上传递如下所示的请求:
proxy_pass http://127.0.0.1:33000;
当我将请求发送到端口80
时,我得到502 Bad Gateway Error
。为什么会这样?
答案 0 :(得分:1)
UWSGI绑定到127.0.0.1
,我在容器上将其更改为0.0.0.0
。并有类似下面的内容:
http-socket=0.0.0.0:1818