有两个容器詹金斯和sonarqube都在网络ci下。
我可以使用链接的主机名和公开端口从jenkins访问sonarqube,但无法使用主机ip和已发布端口进行访问。
# docker exec jenkins nc -zv sonarqube 9000
sonarqube (172.19.0.5:9000) open
# docker exec jenkins nc -zv PHYSICAL_HOST_IP 9000
nc: PHYSICAL_HOST_IP (PHYSICAL_HOST_IP:9000): Host is unreachable
PHYSICAL_HOST_IP
是Docker主机(或物理机)的IP,例如10.x.x.x。
以下是docker-compose配置:
docker-compose.jenkins.yml
version: '3.8'
services:
jenkins:
image: jenkinsci/blueocean
container_name: jenkins
restart: always
external_links:
- sonarqube:sonarqube
ports:
- "8080:8080"
privileged: true
networks:
- ci
networks:
ci:
external: true
docker-compose.sonarqube.yml
version: "3"
services:
sonarqube:
image: sonarqube:8.4.2-community
container_name: sonarqube
restart: always
links:
- db:db
ports:
- "9000:9000"
depends_on:
- db
networks:
- ci
environment:
- SONARQUBE_JDBC_USERNAME=user
- SONARQUBE_JDBC_PASSWORD=password
- SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonarqube
db:
image: postgres:12.4
container_name: postgres
restart: always
networks:
- ci
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
- POSTGRES_DB=sonarqube
networks:
ci:
external: true
网络ci:
[
{
"Name": "ci",
"Id": "...",
"Created": "...",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.19.0.0/16",
"Gateway": "172.19.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
...
},
"Options": {},
"Labels": {}
}
]
非常感谢!
答案 0 :(得分:0)
请尝试在http.nonProxyHost
下的sonar.properties文件中添加主机。
关注这两篇文章以获取更多详细信息:
希望这可以解决您的问题。