Docker-compose服务(sonarqube)无法访问其他服务(postgres)

时间:2019-06-13 09:49:22

标签: postgresql docker docker-compose sonarqube

我有以下sonarqube + postgres docker-compose文件。它在Docker for WindowsDocker for Mac的本地计算机上都可以正常工作。

但是当我将其部署到实时服务器(Ubuntu 18.04)上时,sonarqube无法访问postgres,并且在sonarqube容器日志中出现以下错误:

您知道为什么在实时服务器上会发生这种情况吗?

这些是Docker和Docker-Compose版本:

本地计算机

Docker版本18.09.2,内部版本6247962

Docker-compose版本1.23.2,内部版本1110ad01

服务器

Docker版本18.09.6,内部版本481bc77

Docker-compose版本1.24.0,内部版本0aa5906

version: "3.5"
services:
  sonarqube:
    image: sonarqube:7.7-community    
    ports:
    - "9000:9000"
    depends_on:
    - db
    networks:
    - sonarnet
    environment:
    - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
    - SONARQUBE_JDBC_USERNAME=sonar
    - SONARQUBE_JDBC_PASSWORD=sonar
    - sonar.forceAuthentication=true
    volumes:
    - sonarqubeConf:/opt/sonarqube/conf
    - sonarqubeData:/opt/sonarqube/data
    - sonarqubeBundledPlugins:/opt/sonarqube/lib/bundled-plugins
    - sonarqubeLogs:/opt/sonarqube/logs
  db:
    image: postgres
    networks:
    - sonarnet
    environment:
    - POSTGRES_USER=sonar
    - POSTGRES_PASSWORD=sonar
    volumes:
    - postgresql:/var/lib/postgresql
    - postgresqlData:/var/lib/postgresql/data      
networks:
  sonarnet:
    driver: bridge
volumes:
  sonarqubeConf:
    name: sonarqubeConf
    driver: local
  sonarqubeData:
    name: sonarqubeData
    driver: local 
  sonarqubeBundledPlugins:
    name: sonarqubeBundled
    driver: local
  sonarqubeLogs:
    name: sonarqubeLogs
    driver: local
  postgresql:
    name: postgresql
    driver: local
  postgresqlData:
    name: postgresqlData
    driver: local  

我在sonarqube容器日志中遇到以下错误:

SonarQube Server / 7.7.0.23042 / 1dcac8b8de36b377a1810cc8f1c4c31744e12729
sonarqube_1  | 2019.06.13 09:16:13 INFO  web[][o.sonar.db.Database] Create JDBC data source for jdbc:postgresql://db:5432/sonar
sonarqube_1  | 2019.06.13 09:16:23 ERROR web[][o.s.s.p.Platform] Web server startup failed
sonarqube_1  | java.lang.IllegalStateException: Can not connect to database. Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc.').

postgres容器日志

db_1         | 2019-06-13 11:18:36.548 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1         | 2019-06-13 11:18:36.548 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1         | 2019-06-13 11:18:36.561 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1         | 2019-06-13 11:18:36.579 UTC [24] LOG:  database system was shut down at 2019-06-13 11:18:35 UTC
db_1         | 2019-06-13 11:18:36.585 UTC [1] LOG:  database system is ready to accept connections

更多更新

我在组合文件中添加了另一项服务(jenkins),它已经启动并正在运行,但是我无法从jenkins服务访问数据库服务!例如ping db不起作用!

当我获得他们的桥接网络的网络状态时,我可以看到同时添加了postgres和jenkins,但我什至无法通过jenkins服务内部的IP地址(ping 17.2.22.0.3)ping db进行服务! 我怀疑这与docker compose服务之间的网络有关。 知道为什么会发生吗?

[
    {
        "Name": "pipeline_sonarnet",
        "Id": "754f1d4c5240fc34f0b34faffad61513b95c7c44f89fe15bd66efb7b79c4f53f",
        "Created": "2019-06-13T22:33:58.907722824+01:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.22.0.0/16",
                    "Gateway": "172.22.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "10e84761051c6e6044be3d976ee51dfd70c41c89dc38aab2d3ebcbeb9c2d6129": {
                "Name": "pipeline_db_1",
                "EndpointID": "d8e3b21ffa536c7c437479b5dbaf9a5946177ef87f73cf8e024610ebc8d3c1db",
                "MacAddress": "02:42:ac:16:00:03",
                "IPv4Address": "172.22.0.3/16",
                "IPv6Address": ""
            },
            "c1d042c77b3a0a6f519e11a5a812e38b95ac229244a5d6f28669c4132a104f30": {
                "Name": "pipeline_jenkins_1",
                "EndpointID": "e7592e5de8001ebf4df854c83670552bda78dad51191e215885fd7d58339d98b",
                "MacAddress": "02:42:ac:16:00:02",
                "IPv4Address": "172.22.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "sonarnet",
            "com.docker.compose.project": "pipeline",
            "com.docker.compose.version": "1.24.0"
        }
    }
]

有趣!其他人也有同样的问题,但没有答案: https://forums.docker.com/t/docker-compose-works-on-my-machine-but-not-production/31410

0 个答案:

没有答案