首页 > Web开发 > 详细

[Docker] Driver Bridge network for linking containers

时间:2019-04-05 17:29:49      阅读:145      评论:0      收藏:0      [点我收藏+]

In previous post we have seen how to link two container together by using `--link`:

# docker run -d --name my-mongodb mongo
# docker run -d -p 3000:3000 --link my-mongodb:mongodb --name nodeapp danwahlin/node

 

In this poist, we are going to see how to create brige network, and link contianer inside network.

 

First, we can create a network:

docker network create --driver bridge isolated_network

 

We can inspect our network:

docker network inspect isolated_network

Once we add container into network, this command is helpful.

 

Run the MongoDB container and link it into network, also give it a name ‘mongodb‘

docker run -d --net=isolated_network --name mongodb mongo

 

Run the nodejs container and link it to network, also give it a name ‘nodeapp‘:

docker run -d -p 3000:3000 --net=isolated_network --name nodeapp danwalin/node

 

Linking container into network is useful for tow or three containers, but once we have more containers, it is not convenient to write so many command lines to get job done. Instead we can use Docker Compose for this task.

 

[Docker] Driver Bridge network for linking containers

原文:https://www.cnblogs.com/Answer1215/p/10659062.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!