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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。