Scott's Blog

学则不固, 知则不惑

0%

Docker 部署 Dash 应用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
FROM python:3.7.3
COPY . /app/dash_app

# Set up Oracle
WORKDIR /opt/oracle
RUN apt-get update && apt-get install -y libaio1 wget unzip \
&& cp /app/dash_app/oracle_configs/instantclient-basic-linux.x64-12.2.0.1.0.zip . \
&& unzip instantclient-basic-linux.x64-12.2.0.1.0.zip \
&& rm -f instantclient-basic-linux.x64-12.2.0.1.0.zip \
&& cd /opt/oracle/instantclient* \
&& rm -f *jdbc* *occi* *mysql* *README *jar uidrvci genezi adrci \
&& echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf \
&& ldconfig \
&& mkdir -p /opt/oracle/instantclient_12_2/network/admin \
&& cp /app/dash_app/oracle_configs/tnsnames.ora /opt/oracle/instantclient_12_2/network/admin/ \
&& cp /app/dash_app/oracle_configs/sqlnet.ora /opt/oracle/instantclient_12_2/network/admin/

# Set work dir
WORKDIR "/app/dash_app"
# Install python packages
# RUN pip install -r /app/dash_app/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
RUN pip install -r /app/dash_app/requirements.txt
# Expose port
EXPOSE 8050
CMD [ "gunicorn","run:server","-c","./gunicorn.conf.py"]

Dash 应用还需要一个 WSGI 服务,这里使用 gunicorn,它需要一个配置文件 gunicorn.conf.py ,其文件内容参考:

1
2
3
workers = 5
workers_class = "gevent"
bind = "0.0.0.0:8050"