未分类

基于alpine linux的re:dash docker运行环境

thumbnail

re:dash这套BI系统相信很多人都用过,本人曾经也基于1.0.1版本做过一些汉化及功能增强处理,由于官方的镜像文件比较大,因此今天要讲的就是将目前的正式版v3.0.0移植到alpine linux上

注意事项


  • 特殊依赖项
    • postgresql-dev < 10.0
    • freetds 0.95.95
    • pymssql 2.1.3
  • 解决办法
    • 由于alpine中使用apk add freetds-dev安装的版本为1.0,执行pip install pymssql时会提示not using bundled FreeTDS的错误,解决办法就是将freetds换成0.95.95的版本(参考页面http://pymssql.org/en/stable/freetds.html)

  • 启动脚本redash/bin/docker-entrypoint
    • /usr/local/bin/celery
    • /usr/local/bin/gunicorn
  • 解决办法
    • 由于celery与gunicorn默认安装在/usr/bin/目录下,因此需要软链接过去
    • 命令ln -s /usr/bin/celery /usr/local/bin/celery
    • 命令ln -s /usr/bin/gunicorn /usr/local/bin/gunicorn

Dockerfile配置

由于国内网速不是很稳定,这里我们手动下载文件并配置国内加速

  1. 将以下两个文件下载到Dockerfile文件同级目录

  2. 配置Dockerfile文件

    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
    26
    27
    28
    29
    30
    31
    32
    FROM alpine:3.6
    MAINTAINER wangdong <mail@wangdong.io>

    RUN sed -i -e 's~dl-cdn.alpinelinux.org~mirrors.aliyun.com~g' /etc/apk/repositories
    RUN apk --no-cache add bash build-base g++ make autoconf python-dev py2-pip tzdata nodejs nodejs-npm git pwgen \
    mariadb-dev postgresql-dev libffi-dev linux-headers musl-dev libressl-dev cyrus-sasl-dev libpq && \
    yes | cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

    ADD freetds-0.95.95.tar.gz /opt/
    ADD redash-3.0.0.tar.gz /

    RUN mv /redash-3.0.0 /app && \
    cd /opt/freetds-0.95.95 && \
    ./configure && make && make install && \
    rm -rf /opt/freetds-0.95.95

    WORKDIR /app

    RUN pip --no-cache-dir install \
    -i https://pypi.tuna.tsinghua.edu.cn/simple \
    -r requirements.txt -r requirements_dev.txt -r requirements_all_ds.txt

    RUN node -v && npm -v && \
    npm config set registry https://registry.npm.taobao.org && \
    echo 'sass_binary_site=https://npm.taobao.org/mirrors/node-sass' >> ~/.npmrc && \
    make && \
    rm -rf node_modules && npm cache clear

    RUN ln -s /usr/bin/celery /usr/local/bin/celery && \
    ln -s /usr/bin/gunicorn /usr/local/bin/gunicorn

    ENTRYPOINT ["/app/bin/docker-entrypoint"]

服务启动

  1. 先编译上面的Dockerfile

    1
    docker build -t wangdong/redash:latest .
  2. 新建文件docker-compose.yml

    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
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    version: '2'
    services:
    server:
    image: wangdong/redash:latest
    restart: always
    command: server
    depends_on:
    - postgres
    - redis
    ports:
    - "5000:5000"
    environment:
    C_FORCE_ROOT: 1
    PYTHONUNBUFFERED: 0
    REDASH_LOG_LEVEL: "INFO"
    REDASH_REDIS_URL: "redis://redis:6379/0"
    REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres"
    REDASH_COOKIE_SECRET: veryverysecret
    REDASH_WEB_WORKERS: 4
    worker:
    image: wangdong/redash:latest
    restart: always
    command: scheduler
    environment:
    C_FORCE_ROOT: 1
    PYTHONUNBUFFERED: 0
    REDASH_LOG_LEVEL: "INFO"
    REDASH_REDIS_URL: "redis://redis:6379/0"
    REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres"
    QUEUES: "queries,scheduled_queries,celery"
    WORKERS_COUNT: 2
    redis:
    image: redis:alpine
    restart: always
    postgres:
    image: postgres:alpine
    restart: always
    # volumes:
    # - ./data/postgres/data:/var/lib/postgresql/data
  3. 初始化数据

    1
    docker-compose run --rm server create_db
  4. 启动服务

    1
    docker-compose up
分享到