如何持久化配置&Sonarqube docker 镜像中跨容器调用的分析 [英] How to persist configuration & analytics across container invocations in Sonarqube docker image

查看:35
本文介绍了如何持久化配置&Sonarqube docker 镜像中跨容器调用的分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sonarqube 官方 docker 镜像,不会保留任何配置更改,例如:创建用户、更改 root 密码甚至安装新插件.

Sonarqube official docker image, is not persisting any configuration changes like: creating users, changing root password or even installing new plugins.

一旦容器重新启动,所有配置更改都会消失,安装的插件也会丢失.甚至项目的密钥和它们之前的 QA 分析数据在重新启动后也不可用.

Once the container is restarted, all the configuration changes disappear and the installed plugins are lost. Even the projects' keys and their previous QA analytics data is unavailable after a restart.

在使用 Sonarqube 的官方 docker 镜像时,我们如何持久化数据?

How can we persist the data when using Sonarqube's official docker image?

推荐答案

  • Sonarqube 映像带有一个临时的 h2 数据库引擎,不建议将其用于生产,并且不会在容器重启后持续存在.
  • 我们需要建立自己的数据库,并在启动容器时将其指向 Sonarqube.
  • Sonarqube docker 镜像暴露了两个卷 "$SONARQUBE_HOME/data", "$SONARQUBE_HOME/extensions"Sonarqube Dockerfile.
  • 由于我们希望跨调用保留数据,因此我们需要确保已设置生产级数据库并链接到 Sonarqube,并创建扩展目录并将其作为卷安装在主机上,以便所有下载的插件跨容器调用可用,并且可以被多个容器使用(如果需要).

    Since we wanted to persist the data across invocations, we need to make sure that a production grade database is setup and is linked to Sonarqube and the extensions directory is created and mounted as volume on the host machine so that all the downloaded plugins are available across container invocations and can be used by multiple containers (if required).

    数据库设置:

    create database sonar;
    grant all on sonar.* to `sonar`@`%` identified by "SOME_PASSWORD";
    flush privileges;
    
    # since we do not know the containers IP before hand, we use '%' for sonarqube host IP.
    

    没有必要创建表,Sonarqube 会在找不到它们时创建它们.

    It is not necessary to create tables, Sonarqube creates them if it doesn't find them.

    启动 Sonarqube 容器:

    Starting up Sonarqube container:

    # create a directory on host
    mkdir /server_data/sonarqube/extensions
    mkdir /server_data/sonarqube/data # this will be useful in saving startup time
    
    # Start the container
    docker run -d 
        --name sonarqube 
        -p 9000:9000 
        -e SONARQUBE_JDBC_USERNAME=sonar 
        -e SONARQUBE_JDBC_PASSWORD=SOME_PASSWORD 
        -e SONARQUBE_JDBC_URL="jdbc:mysql://HOST_IP_OF_DB_SERVER:PORT/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance" 
        -v /server_data/sonarqube/data:/opt/sonarqube/data 
        -v /server_data/sonarqube/extensions:/opt/sonarqube/extensions 
        sonarqube
    

    这篇关于如何持久化配置&Sonarqube docker 镜像中跨容器调用的分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆