作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在TeamCity
docker agent上测试我的应用程序。应用程序在gradle中运行内部docker。
这是我的docker-compose.yml
:
version: '3'
services:
db:
image:
docker.int.address.com/postgres:9.6
ports:
- 5432:5432
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
networks:
my_net:
ipv4_address: 172.19.0.3
networks:
my_net:
ipam:
driver: default
config:
- subnet: 172.19.0.0/24
[13:13:59][docker] Successfully started process 'command 'docker-compose''
[13:14:00][docker] Some networks were defined but are not used by any service: my_net
[13:14:00][docker] db uses an image, skipping
[13:14:00][docker] Starting process 'command 'docker-compose''. Working directory: /checkout Command: docker-compose -f /checkout/docker-compose.yml --version
[13:14:00][docker] Successfully started process 'command 'docker-compose''
[13:14:00][docker] Starting process 'command 'docker-compose''. Working directory: /checkout Command: docker-compose -f /checkout/docker-compose.yml --version
[13:14:00][docker] Successfully started process 'command 'docker-compose''
[13:14:01][docker] Starting process 'command 'docker-compose''. Working directory: /checkout Command: docker-compose -f /checkout/docker-compose.yml up -d
[13:14:01][docker] Successfully started process 'command 'docker-compose''
[13:14:01][docker] Some networks were defined but are not used by any service: my_net
[13:14:02][docker] Recreating checkout_db_1 ...
[13:14:02][docker] Recreating checkout_db_1
[13:14:03][docker] Starting process 'command 'docker-compose''. Working directory: /checkout Command: docker-compose -f /checkout/docker-compose.yml --version
[13:14:03][docker] Successfully started process 'command 'docker-compose''
[13:14:04][docker] Starting process 'command 'docker-compose''. Working directory: /checkout Command: docker-compose -f /checkout/docker-compose.yml config --services
[13:14:04][docker] Successfully started process 'command 'docker-compose''
[13:14:04][docker] Starting process 'command 'docker-compose''. Working directory: /checkout Command: docker-compose -f /checkout/docker-compose.yml ps -q db
[13:14:04][docker] Successfully started process 'command 'docker-compose''
[13:14:05][docker] [1A [2K
[13:14:05][docker] Recreating checkout_db_1 ... done
[13:14:05][docker] [1BSome networks were defined but are not used by any service: my_net
[13:14:05][docker] Container ID of service db is fc3d436189aa1e455a7f4e8524f99605e87ce72b214844097534cbf4a89a4d77
[13:14:05][docker] Starting process 'command 'docker''. Working directory: /checkout Command: docker inspect fc3d436189aa1e455a7f4e8524f99605e87ce72b214844097534cbf4a89a4d77
[13:14:05][docker] Successfully started process 'command 'docker''
**[13:14:06][docker] Will use 172.17.0.1 (network bridge) as host of db**
[13:14:06][docker] Will use com.address.gradle.dockercompose.ServiceHost(172.17.0.1, NetworkGateway) as host of service db
[13:14:06][docker] Exposed TCP port on service 'db:5432' will be available as 5432
[13:14:06][docker] Starting process 'command 'docker''. Working directory: /checkout Command: docker inspect fc3d436189aa1e455a7f4e8524f99605e87ce72b214844097534cbf4a89a4d77
[13:14:06][docker] Successfully started process 'command 'docker''
[13:14:06][docker] Probing TCP socket on 172.17.0.1:5432 of service 'db_1'
[13:16:14][docker] Waiting for TCP socket on 172.17.0.1:5432 of service 'db_1' (Connection timed out (Connection timed out))
[13:18:22][docker] Waiting for TCP socket on 172.17.0.1:5432 of service 'db_1' (Connection timed out (Connection timed out))
[13:20:30][docker] Waiting for TCP socket on 172.17.0.1:5432 of service 'db_1' (Connection timed out (Connection timed out))
[13:22:38][docker] Waiting for TCP socket on 172.17.0.1:5432 of service 'db_1' (Connection timed out (Connection timed out))
[13:24:47][docker] Waiting for TCP socket on 172.17.0.1:5432 of service 'db_1' (Connection timed out (Connection timed out))
docker-compose.yml
写什么,以便它可以找到正确的主机?
最佳答案
在应用程序服务中,该服务与删除主机连接,请放置远程主机的名称。打开两个服务,在控制台上运行docker ps
。数据库服务的名称为somedirectory_db
。将其作为连接字符串的一部分放在您的应用程序逻辑中;例:DSN=host:somdirectory_db;port=3306;schema=some_database
本质上,如果两个服务都在同一网络上,则可以将服务名称用作可解析的DSN地址。
引用:How to reach docker containers by name instead of IP address?
关于java - 如何在Docker中设置服务主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46407192/
我是一名优秀的程序员,十分优秀!