刚初学 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;
}
}