刚初学 Docker, 有些地方不是很理解,写了一个镜像,单启用 uwsgi 的话没有问题,想请教一下, docker 内部 nginx 和 wsgi 该如何通信呢? 我是 build 镜像后 ,先 docker run -p 8010:80 image 启动 docker 和 uwsgi 然后 docker exec container_id /etc/init.d/nginx start 启动 nginx 的
Dockerfile
FROM ubuntu:16.04
RUN rm -rf /etc/apt/sources.list
COPY ./sources.list /etc/apt/sources.list(换了阿里的 ubuntu 源)
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y python2.7 python-dev python-pip python-setuptools git ssh ca-certificates git-core nginx
RUN mkdir /www
RUN mkdir /www/ini/
RUN mkdir /www/public/
RUN mkdir /www/log/
RUN touch /www/log/project.log
COPY ./requirements.txt /www/ini/requirements.txt
COPY ./uwsgi.ini /www/ini/uwsgi.ini
COPY ./site.conf /etc/nginx/sites-enabled/site.conf
RUN pip install --upgrade pip
RUN pip install -r /www/ini/requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
RUN pip install uwsgi -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
WORKDIR /www/public
RUN git config --global user.name "my name"
RUN git config --global user.email "my email"
RUN git clone http://xxxxxx:xxxxxx(此处应有隐藏)@git.coding.net/chengxiao/yuqingweb.git
EXPOSE 80
CMD ["uwsgi", "--ini","/www/ini/uwsgi.ini"]
uwsgi 配置
# Django-related settings
[uwsgi]
socket = /www/ini/uwsgi.sock
# the base directory (full path)
chdir = /www/public/project/
# Django s wsgi file
module = project.wsgi
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 6
listen = 100
buffer-size = 8192
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
Nginx 配置
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name localhost; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /www/public/project/media;
}
location /static {
alias /www/public/project/static;
}
location / {
include uwsgi_params;
uwsgi_pass unix:///www/ini/uwsgi.sock;
}
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.