docker-compose搭建sonarqube

创建挂载数据目录

mkdir -p /opt/sonarqube/conf
mkdir -p /opt/sonarqube/data
mkdir -p /opt/sonarqube/extensions
mkdir -p /var/lib/postgresql/data

编写docker-compose.yaml

version: "2"
services:
  sonarqube:
    image: sonarqube
    restart: always
    ports:
      - "9900:9000"
    depends_on:
      - db
    networks:
      - sonarnet
    environment:
      - SONAR_JDBC_USERNAME=sonar
      - SONAR_JDBC_PASSWORD=sonar123
      - SONAR_JDBC_URL=jdbc:postgresql://db:5432/sonarqube
      - SONARQUBE_JDBC_USERNAME=sonar
      - SONARQUBE_JDBC_PASSWORD=sonar123
      - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonarqube
    volumes:
      - /opt/sonarqube/conf:/opt/sonarqube/conf
      - /opt/sonarqube/data:/opt/sonarqube/data
      - /opt/sonarqube/extensions:/opt/sonarqube/extensions

  db:
    image: postgres
    restart: always
    networks:
      - sonarnet
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=sonar123
      - POSTGRES_DB=sonarqube
    volumes:
      - /var/lib/postgresql/data:/var/lib/postgresql/data

networks:
  sonarnet:
    driver: bridge

启动

docker-compose up

访问

ip地址+9900

你可能感兴趣的:(docker,sonarqube)