赞
踩
docker很方便的给我们用容器的方式解决了服务隔离运行,同时也产生了一个需要内部网络多个容器之间发生通讯,其实比较简单就可以实现,方式为:创建一个网络组、然后需要内部通讯的容器都加入到这个网络组中,然后这写加入的容器都是同一个网段,就可以通讯了。
- [root@ecs-b3bf-0225793 ~]#
- [root@ecs-b3bf-0225793 ~]# docker network create --driver bridge mq-bridge
- 5e9af94588646f049559ba049facc50c1c8b3c8a3d06f7cd8c44df5908bf0125
- [root@ecs-b3bf-0225793 ~]#
- [root@ecs-b3bf-0225793 ~]#
- [root@ecs-b3bf-0225793 ~]# docker network ls
- NETWORK ID NAME DRIVER SCOPE
- 6f66df95e8ce app_net bridge local
- 95746a181dfb bridge bridge local
- 9c82ac52a997 docker_default bridge local
- d86404029f06 docker_work bridge local
- 8d350f2a2209 host host local
- 5e9af9458864 mq-bridge bridge local
- 2f1631ba396f none null local
- [root@ecs-b3bf-0225793 ~]#
如上,我们的网络组就可以使用了:mq-bridge
- [root@ecs-b3bf-0225795 conf]#
- [root@ecs-b3bf-0225795 conf]# docker run -d -p 10911:10911 -p 10909:10909 \
- -v /home/docker/rocketmq/logs:/root/logs \
- -v /home/docker/rocketmq/store:/root/store \
- -v /home/docker/rocketmq/conf/broker.conf:/opt/rocketmq-latest/conf/broker.conf \
- --name rmqbroker --link rmqnamesrv:namesrv --net=mq-bridge \
- -e "NAMESRV_ADDR=namesrv:9876" \
- -e "MAX_POSSIBLE_HEAP=200000000" \
- rocketmqinc/rocketmq:latest sh mqbroker
- 3046c85168b8ee4e6f61c68412c7495c596b4c366eb9091d62205ad5f97eef34
- [root@ecs-b3bf-0225795 rocketmq]#
如上最重要的信息:--net=mq-bridge
- [root@ecs-b3bf-0225795 conf]#
- [root@ecs-b3bf-0225795 conf]# docker inspect mq-bridge
ok,多个容器之间的IP就有了,具体再改相应的IP就可以内网通信了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。