码迷,mamicode.com
首页 > Web开发 > 详细

[Docker] Driver Bridge network for linking containers

时间:2019-04-05 16:49:53      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:href   spec   ref   com   one   http   run   .com   instead   

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

标签:href   spec   ref   com   one   http   run   .com   instead   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!