Regarding springcloud deployment docker multi-server deployment and directory sharing issues

A problem I encountered when doing Alipay certificate mode is that the service in the docker container cannot obtain the certificate file of the host machine.

It all confused me

Then think about docker itself, which is a small virtual machine, and think that its internal directory structure is similar to that of the host machine.

I know that what it is looking for is not the path on my host but its own virtual directory.

I am a microservice and when deploying multiple servers, I encounter service connections between servers and cannot access them.

In fact, the reason is very simple. After docker starts the container, the IP registered on nacos is the virtual IP in docker. Each docker container will obtain a virtual IP from the host and be exposed, and what nacos obtains is the virtual IP of this docker. Moreover, after gateway resolution, the request will use this virtual IP. This IP does not exist in the physical server AB, so it will time out.

The following docker startup command is the container mapping the host's real IP and sharing the host's /root/alipay directory

docker run -d -it -v /root/alipay:/root/alipay(此为共享目录) --network=host(此命令映射宿主机真实ip)  demo:latest

 The following is the mapping container shared directory file

docker run -it -v /root/alipay:/root/alipay(此为共享目录) demo:latest

 The following is the real IP of the mapping container host

 docker run -d --network=host(此命令映射宿主机真实ip)  demo:latest

 

 

 

 

Guess you like

Origin blog.csdn.net/qq_37544675/article/details/117786896