nacos+gateway+docker 不能访问其他服务器项目

问题出现如题
问题描述:请求通过网关转发到服务出现网络ip:端口请求超时

Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: No route to host: /172.17.0.2:9002
Caused by: java.net.ConnectException: finishConnect(..) failed: No route to host
        at io.netty.channel.unix.Errors.throwConnectException(Errors.java:124) ~[netty-transport-native-unix-common-4.1.43.Final.jar!/:4.1.43.Final]
        at io.netty.channel.unix.Socket.finishConnect(Socket.java:243) ~[netty-transport-native-unix-common-4.1.43.Final.jar!/:4.1.43.Final]
        at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.doFinishConnect(AbstractEpollChannel.java:660) ~[netty-transport-native-epoll-4.1.43.Final-linux-x86_64.jar!/:4.1.43.Final]
        at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:637) ~[netty-transport-native-epoll-4.1.43.Final-linux-x86_64.jar!/:4.1.43.Final]
        at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:524) ~[netty-transport-native-epoll-4.1.43.Final-linux-x86_64.jar!/:4.1.43.Final]
        at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:492) ~[netty-transport-native-epoll-4.1.43.Final-linux-x86_64.jar!/:4.1.43.Final]
        at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:407) ~[netty-transport-native-epoll-4.1.43.Final-linux-x86_64.jar!/:4.1.43.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050) ~[netty-common-4.1.43.Final.jar!/:4.1.43.Final]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.43.Final.jar!/:4.1.43.Final]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.43.Final.jar!/:4.1.43.Final]
        at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_241]

这里发现我们这边gateway连接使用的docker 内部的内网ip

解决办法:
指定docker容器网络使用宿主机网络
在启动容器时指定网络连接方式,在命令中增加 --network=host 参数
例如 docker run -di --name=user -p 9002:9002 -v/etc/localtime:/etc/localtime:ro --network=host -e TZ=Asia/Shanghai -e file.encoding=“utf-8” 47.96.92.225:5000/user-server:1.0.0-SNAPSHOT --spring.profiles.active=“prod”

docker --network 几个参数的区别

https://www.jianshu.com/p/2d02bb9a9da5

你可能感兴趣的:(docker)