在docker中通过nginx和gunicorn服务烧瓶
玩烧瓶,我想建立一个真正的设置并在docker中运行.这意味着应通过Nginx和Gunicorn来盛装烧瓶.我设置了一个示例代码存储库 https://github.com/geoHeil/pythonServing ,但到目前为止可以不能让Nginx正常工作.
Playing around with flask I would like to get a real setup up and running in docker. This means flask should be served via nginx and gunicorn. I set up a sample code repository https://github.com/geoHeil/pythonServing but so far can't get nginx to work properly.
烧瓶在application:5000
上提供服务,码头工人应将应用程序解析为其各自的名称.
Flask is served on application:5000
, docker should resolve application to its respective name.
Nginx的配置如下:
Nginx config is as follows:
server {
listen 8080;
server_name application;
charset utf-8;
location / {
proxy_pass http://application:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
对我来说看起来不错.到目前为止,我找不到问题.
which looks good to me. So far I cant find the problem.
撰写文件在这里.启动命令是
compose file is here. Command to start was
docker-compose build
docker-compose up
version: '2'
services:
application:
restart: always
build: ./application
command: gunicorn -w 4 --bind :5000 wsgi:application
links:
- db
expose:
- "5000"
ports:
- "5000:5000"
nginx:
restart: always
build: ./nginx
links:
- application
expose:
- 8080
ports:
- "8880:8080"
您的 nginx 配置文件位于错误的位置.
Your nginx config file is in a wrong location.
修复步骤:
sudo docker-compose down
删除nginx图片:
sudo docker images
sudo docker rmi
REPOSITORY TAG IMAGE ID CREATED SIZE
pythonserving_nginx latest 152698f13c7a About a minute ago 54.3 MB
sudo docker rmi pythonserving_nginx
现在更改nginx Dockerfile :
Now change the nginx Dockerfile:
FROM nginx:1.11.8-alpine
MAINTAINER geoheil
ADD sites-enabled.conf /etc/nginx/conf.d/sites-enabled.conf
请注意nginx配置的位置.
Please note the location of nginx config.
现在尝试使用此docker-compose文件(使用用户定义的网络):
Now try this docker-compose file (Using User-defined Networks):
version: '2'
services:
application:
restart: always
build: ./application
command: gunicorn -w 4 --bind :5000 wsgi:application
networks:
- testnetwork
expose:
- "5000"
ports:
- "5000:5000"
db:
restart: always
image: postgres:9.6.1-alpine
networks:
- testnetwork
ports:
- "5432:5432"
environment:
- POSTGRES_USER=d
- POSTGRES_PASSWORD=d
- POSTGRES_DB=d
volumes:
- ./postgres:/var/lib/postgresql
nginx:
restart: always
build: ./nginx
networks:
- testnetwork
expose:
- 8080
ports:
- "8880:8080"
networks:
testnetwork:
然后拿起容器:
sudo docker-compose up