gpt4 book ai didi

docker - Docker组成的持续集成

转载 作者:行者123 更新时间:2023-12-02 21:22:24 24 4
gpt4 key购买 nike

我是docker技术的新手。我实际上有一个任务要使用docker-compose创建一个用于持续集成的环境,这是我所做的docker-compose,但是当运行docker-compose时,我仍然遇到一些错误,例如声纳异常:数据库连接失败。
实际的操作系统是VirtualBox窗口下的oracle linux。

version: '2'

networks:
devnet:
driver: bridge

services:
nexus:
image: sonatype/nexus
container_name: nexus
ports:
- "8081:8081"
networks:
- devnet
volumes:
- "/opt/nexus/:/var/lib/nexus"

jenkins:
image: jenkins
container_name: jenkins
ports:
- "8080:8080"
networks:
- devnet
volumes:
- "$PWD/jenkins:/var/jenkins_home"


mongodb:
image: mongo
networks:
- devnet
ports:
- 8085:8085
environment:
- MONGODB_USER=root
- MONGODB_DATABASE=srsmongodb
- MONGODB_PASS=root
volumes:
- /srv/docker/mongodb:/var/lib/mongodb
restart: always

tomcat:
image: tomcat
container_name: tomcat
networks:
- devnet
volumes:
- ./target/ROOT.war:/usr/local/tomcat/webapps/ROOT.war
ports:
- 8084:8084
restart: always

sonarqube:
image: sonarqube
container_name: sonarqube
restart: always
ports:
- "9000:9000"
networks:
- devnet
environment:
- SONARQUBE_JDBC_USERNAME=root
- SONARQUBE_JDBC_PASSWORD=root
- SONARQUBE_JDBC_URL=jdbc:mysql://sonardb:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
volumes:
- "/opt/sonar/:/var/lib/sonar"
depends_on:
- mysql

mysql:
image: mysql
networks:
- devnet
restart: always
ports:
- 3307:3307
tty: true
volumes:
- /opt/mysql:/var/lib/mysql:rw
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=sonardb

最佳答案

似乎您正在将MySQL数据库的DNS名称与MySQL数据库的名称混淆。在您的示例中,sonarqube图像的JDBC URL应为:

jdbc:mysql://mysql:3306/sonardb?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

在Docker Compose中创建网络时,该网络中的服务将通过与该服务相同的DNS名称来使用。在这种情况下, mysql将解析为MySQL容器的IP地址。您提供给 mysql服务的环境变量将创建一个名为 sonardb的数据库。

具体参见 https://docs.docker.com/compose/networking/#links的“链接”部分:

by default, any service can reach any other service at that service’s name. In the following example, db is reachable from web at the hostnames db and database

关于docker - Docker组成的持续集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43924834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com