1.Dockerfile
FROM centos:7
MAINTAINER xf <1182900548@qq.com>
RUN mkdir /data
RUN mkdir /data/code
RUN mkdir /data/uwsgi
ADD ./ys_backend /data/code/ys_backend
# 安装python3 配置pip
RUN yum -y install python3
RUN python3 -m pip install --upgrade pip -i https://pypi.douban.com/simple/
#创建虚拟环境
RUN python3 -m venv /root/venv
RUN /root/venv/bin/python3 -m pip install --upgrade pip -i https://pypi.douban.com/simple/
RUN /root/venv/bin/pip3 install -r /data/code/ys_backend/requirements.txt -i https://pypi.douban.com/simple/
#配置uwsgi
RUN yum install -y gcc gcc-c++ make pcre-devel zlib-devel
RUN yum install -y python3-devel
RUN pip install uwsgi -i https://pypi.douban.com/simple/
ADD ys_uwsgi.ini /data/uwsgi
ADD ys_uwsgi.log /data/uwsgi
ADD ys_uwsgi.pid /data/uwsgi
RUN uwsgi --ini /data/uwsgi/ys_uwsgi.ini
#配置nginx
RUN yum -y install epel-release
RUN yum -y install nginx
#指定http和https端口
EXPOSE 443
EXPOSE 80
RUN rm -rf /etc/nginx/nginx.conf
ADD nginx.conf /etc/nginx/
#关闭守护进程
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
CMD uwsgi --ini /data/uwsgi/ys_uwsgi.ini && nginx -c /etc/nginx/nginx.conf
2.构建镜像
docker build -t "ys:latest" .
3.启动容器
docker run -d -p 80:80 -name ysls ys