docker安装部署superset2.0,并且汉化
编写Dockerfile
mkdir -p /data/superset
vi /data/superset/Dockerfile
Dockerfile内容如下
FROM apache/superset:2-0
# 切换用户为root
USER root
#设置时区
ENV TZ=Asia/Shanghai
RUN cp /usr/share/zoneinfo/Asia/Shanghai superset:/etc/localtime
# 安装mysql依赖
RUN pip install mysqlclient
RUN pip install sqlalchemy-redshift
# 创建环境变量文件
RUN echo 'create superset_config.py file'
RUN touch /app/pythonpath/superset_config.py
# 往变量文件里面追加数据连接地址
RUN echo 'superset_config.py file write SQLALCHEMY_DATABASE_URI'
RUN echo 'SQLALCHEMY_DATABASE_URI = "mysql://账号:密码@链接地址:3306/superset?charset=utf8"' > /app/pythonpath/superset_config.py
# 汉化
RUN sed -i "s/BABEL_DEFAULT_LOCALE = \"en/BABEL_DEFAULT_LOCALE = \"zh/g" /app/superset/config.py
RUN sed -i "s/LANGUAGES = {}/# LANGUAGES = {}/g" /app/superset/config.py
RUN apt-get update && apt-get install python3-babel -y
RUN pybabel compile -d /app/superset/translations
# 处理导出中文乱码
RUN sed -i "s/CSV_EXPORT = {\"encoding\": \"utf-8\"}/CSV_EXPORT = {\"encoding\": \"utf-8-sig\"}/g"
# 切换回superset用户, 切回原因是superset命令只在这个用户里面可以用
USER superset
# 启动时执行
ENTRYPOINT ["sh", "-c", "superset fab create-admin \
--username admin \
--firstname admin \
--lastname admin \
--email 1021907330@qq.com \
--password admin &&\
superset db upgrade && \
superset init && \
sh -c /usr/bin/run-server.sh"]
生成镜像
docker build . -t xxxx/superset:2.0
启动容器
docker run -d -p 8088:8088 --name superset xxxx/superset:2.0