dapi 基於Django的輕量級測試平臺八 Docker部署

QQ羣:529063263python

GitHub:https://github.com/yjlch1016/dapimysql

 

採用Docker+Supervisor+Nginx+uWSGI+Djangonginx

1、Dockerfile文件:git

FROM ubuntu:18.04
# 基礎鏡像

MAINTAINER yangjianliang <526861348@qq.com>
# 做者

RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
# 設置apt源爲阿里雲源

RUN apt-get clean && \
    apt-get update && \
    apt-get upgrade -y
# 檢查軟件包並升級

RUN apt-get install -y \
    git \
    python3 && \
    apt-get update && \
    apt-get install -y \
    python3-dev \
    python3-setuptools && \
    apt-get update && \
    apt-get install -y \
    python3-pip && \
    apt-get update && \
    apt-get install -y \
    nginx \
    supervisor &&\
    apt-get update && \
    ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    apt-get install -y \
    tzdata && \
    rm -rf /var/lib/apt/lists/*
# 安裝軟件

RUN echo "daemon off;" >> /etc/nginx/nginx.conf
COPY deploy_conf/nginx-app.conf /etc/nginx/sites-available/default
COPY deploy_conf/supervisor-app.conf /etc/supervisor/conf.d/
COPY deploy_conf/pip.conf /root/.pip/pip.conf
# 複製配置文件

RUN pip3 install https://codeload.github.com/sshwsfc/xadmin/zip/django2
COPY requirements.txt /django/dapi/
RUN pip3 install -r /django/dapi/requirements.txt
# 安裝Python依賴庫

COPY . /django/dapi/
RUN sed -i '35,36d' /usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/base.py && \
sed -i '145,146d' /usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/operations.py && \
sed -i '93d' /usr/local/lib/python3.6/dist-packages/django/forms/boundfield.py
# 複製其他代碼並修改Django源碼

EXPOSE 80
# 暴露80端口

CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisor-app.conf"]
# 啓動supervisor並加載配置文件github

 

2、打包:sql

docker build -t dapi .docker

等待一下子django

網速慢的話十分鐘吧ubuntu

 

3、運行:api

docker run -d --name dapi1.0 -p 80:80 dapi:latest

# 啓動容器並在後臺運行,暴露80端口,並取個別名爲dapi1.0

 

docker inspect dapi1.0

# 查看容器IP地址

 

docker exec -it dapi1.0 /bin/bash

# 進入容器內部

supervisord -c /etc/supervisor/conf.d/supervisor-app.conf

# 手動啓動supervisor

 

訪問(宿主機的IP地址):

http://192.168.1.102/

帳號:admin

密碼:test123456

 

後臺:

http://192.168.1.102/admin/

帳號:admin

密碼:test123456

 

相關文章
相關標籤/搜索