Communication between containers
One-way communication
# 运行一个名字是web的tomcat容器 并且链接到database容器,可以进入容器内直接ping database,可以在容器能查看到配置到了/etc/hosts的文件
docker run -d --name web --link database tomcat
Bridge two-way communication
- List the current docker network service details
docker network ls
- New bridge
docker network create -d bridge my-bridge
- Connect the container to the bridge
docker network connect my-bridge web
docker network connect my-bridge database
Data sharing between containers
-
Mount the host directory by setting -v
-
format:
-
docker run --name container name -v host path: mirror name of the mount path in the container
-
Share the mount point in the container via --volumes-from
-
Create a shared container
-
docker create --name webpage -v /webapps:/tomcat/webapps tomcat /bin/true
-
Shared container mount point
-
docker run --volumes-from webpage --name t1 -d tomcat