在Docker中的多个容器中共享相同的资源
我需要设置一个容器卷使用多个容器。
例如:
Container 1(web app1): volume path -v /var/www/html/ Container 2 (web app2): volume path -v /var/www/html/ Container 3(Commaon Files): volume path -v /var/www/html/
我需要设置Container-3 Common文件使用其他两个容器。
我如何实现这一点。
你应该命名你的卷,以便你可以挂载他们的名字,而不是容器。 所以:
docker run -d --name web1 -v web1-html:/var/www/html web-img docker run -d --name web2 -v web2-html:/var/www/html web-img docker run -d --name common -v web1-html:/var/www/web1/html \ -v web2-html:/var/www/web2/html your-img
使用您的两个Web应用程序今天创build的卷,您将看到它们在docker volume ls
下用一个guid docker volume ls
。 通过给他们一个名字,你可以很容易地在其他容器中重用这些卷。