之前公司要么是单体架构, 要么是入职的时候已经配置好了微服务, 上家是 nacos+ dubbo, 楼主在想学习一下 docker-comopose 部署 spring cloud , 后期转入 k8s.
楼主在 wsl2 运行 consul+ spring-cloud 的一个 provider 模块, docker-compose 里的 consul 跑得很成功, windows 的 provider 也跑得很成功, 但 docker-compose 里的 provider 死活都无法访问 consul, 下面贴出 dockerfile 和 docker-compose.yml
version: '3'
services:
consul-node1:
image: bitnami/consul
environment:
- CONSUL_BOOTSTRAP_EXPECT=3
- CONSUL_CLIENT_LAN_ADDRESS=0.0.0.0
- CONSUL_DISABLE_KEYRING_FILE=true
- CONSUL_RETRY_JOIN_ADDRESS=consul-node1
ports:
- '8300:8300'
- '8301:8301'
- '8301:8301/udp'
- '8500:8500'
- '8600:8600'
- '8600:8600/udp'
volumes:
- 'consul-node1_data:/bitnami'
consul-node2:
image: bitnami/consul
environment:
- CONSUL_BOOTSTRAP_EXPECT=3
- CONSUL_CLIENT_LAN_ADDRESS=0.0.0.0
- CONSUL_DISABLE_KEYRING_FILE=true
- CONSUL_RETRY_JOIN_ADDRESS=consul-node1
- CONSUL_ENABLE_UI=false
volumes:
- 'consul-node2_data:/bitnami'
consul-node3:
image: bitnami/consul
environment:
- CONSUL_BOOTSTRAP_EXPECT=3
- CONSUL_CLIENT_LAN_ADDRESS=0.0.0.0
- CONSUL_DISABLE_KEYRING_FILE=true
- CONSUL_RETRY_JOIN_ADDRESS=consul-node1
- CONSUL_ENABLE_UI=false
volumes:
- 'consul-node3_data:/bitnami'
provider-impl:
container_name: provider-impl
build:
context: ./jar/provider-impl
dockerfile: Dockerfile
ports:
- "8504:8504"
command: "--spring.config.location=/app/config/application.properties"
volumes:
consul-node1_data:
driver: local
consul-node2_data:
driver: local
consul-node3_data:
driver: local
provider 的配置文件
provider.name=p1
server.port=8504
spring.application.name=consul-provider
spring.cloud.consul.i=127.0.0.1
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.prefer-ip-address=true
spring.cloud.consul.discovery.heartbeat.enabled=true
spring.cloud.consul.discovery.health-check-path=health
spring.cloud.consul.discovery.service-name=service-provider
spring.datasource.driver-class-name=com.p6spy.engine.spy.P6SpyDriver
spring.datasource.url=jdbc:p6spy:mysql://127.0.0.1:3306/blog?allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.name=mysql
spring.datasource.username=root
spring.datasource.password=root
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
mybatis-plus.global-config.db-config.logic-delete-field=deletedAt
mybatis-plus.global-config.db-config.logic-not-delete-value=null
mybatis-plus.global-config.db-config.logic-delete-value=UNIX_TIMESTAMP()
FROM adoptopenjdk:11-jdk-hotspot-focal
VOLUME /tmp
ADD c-consul-provider-impl*.jar /app/provider-impl.jar
ADD config /app/config
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/provider-impl.jar"]
也试过在 docker-compose.yml 添加网络, 但也无法生效,报错信息如下: com.ecwid.consul.transport.TransportException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:8500 [/127.0.0.1] failed: Connection refused (Connection refused)
搞了一晚上三个多小时都没解决...要说连不上 127.0.0.1:8500, 不知道为什么能连上 mysql, mysql 是跑在 wsl 上没有使用 docker, 求大佬帮助
1
ccppgo OP [![xELCOe.md.png]( https://s1.ax1x.com/2022/09/25/xELCOe.md.png)]( https://imgse.com/i/xELCOe)
访问 consul 如图 |
2
mmdsun 2022-09-27 08:04:15 +08:00 via iPhone
127.0.0.1 都换成你电脑内网 IP 地址试试看。
|