Dockerfile
FROM ubuntu:18.04
# 安装git、python、nginx、supervisor、redis、mongodb等,并清理缓存
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y software-properties-common && \
add-apt-repository ppa:jonathonf/python-3.6 -y && \
apt-get update && \
apt-get install -y git python3.6 python3-pip nginx vim supervisor mongodb libsm6 libxrender1 libxext-dev ffmpeg redis-server && \
pip3 install --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple pip setuptools && \
rm -rf /var/lib/apt/lists/* && \
echo "daemon off;" >> /etc/nginx/nginx.conf && \
mkdir /home/EDA_SERVER && \
mkdir -p /data/db
# nginx、supervisor、时区配置
COPY nginx-app.conf /etc/nginx/sites-available/default
COPY supervisor-app.conf /etc/supervisor/conf.d/
COPY localtime /etc/localtime
COPY supervisord.conf /etc/supervisor/supervisord.conf
# 安装项目所需python第三方库及将项目拷贝进镜像中
COPY EDA_SERVER /home/EDA_SERVER
RUN python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r /home/EDA_SERVER/requirements.txt && \
cd /home/EDA_SERVER && \
python3 manage.py makemigrations inquest server && \
python3 manage.py migrate
EXPOSE 80
CMD ["supervisord", "-n"]
nginx-app.conf
upstream django {
server 0.0.0.0:8000;
}
server {
listen 80 default_server;
server_name django;
charset utf-8;
client_max_body_size 75M;
location /media {
alias /home/EDA_SERVER/media;
}
location /static {
alias /home/EDA_SERVER/static;
}
location /static/admin {
alias /usr/local/lib/python3.6/dist-packages/django/contrib/admin/static/admin;
}
location / {
proxy_pass http://django;
}
location /ws {
proxy_pass http://django;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
supervisord.conf
; supervisor config file
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = /etc/supervisor/conf.d/*.conf
[inet_http_server]
port=0.0.0.0:9000
username=admin
password=123456
supervisor-app.conf
[program:daphne]
directory=/home/EDA_SERVER
command=daphne -b 0.0.0.0 -p 8000 --proxy-headers EDA_SERVER.asgi:application
autostart=true
autorestart=true
stdout_logfile=/tmp/websocket.log
redirect_stderr=true
[program:nginx-app]
command = /usr/sbin/nginx
[program:redis]
command = redis-server
[program:mongodb]
command = mongod
部分注释说明
EDA_SERVER为项目目录
localtime为时区文件,一般是/usr/share/zoneinfo/Asia/ShangHai
tree
├── Dockerfile
├── EDA_SERVER
├── localtime
├── nginx-app.conf
├── supervisor-app.conf
└── supervisord.conf
制作镜像的命令为
docker build -t eda_server:v0.1 .