我可以将同一卷安装到多个Docker容器吗 [英] Can I mount same volume to multiple docker containers
问题描述
我需要将应用程序日志共享到已安装的卷。
我想将相同的卷装载到所有docker容器以保留日志。
有可能吗?它会影响应用程序在每个容器上运行吗?
I need to share the application logs to mounted volume. I want to mount same volume to all docker containers to keep the logs. is it possible? will it effect the application running on each container?
docker run -d --name C1 -v /home/ubuntu/logs:/usr/local/apache/htdocs/ httpd
docker run -d --name C2 -v /home/ubuntu/logs:/etc/app/logs my-docker-image:latest
docker run -d --name C3 -v /home/ubuntu/logs:/usr/logs TestImage:latest
推荐答案
是的,您可以将卷的相同位置添加到许多Docker容器中。
Yes you can add same location as a volume to many docker containers.
另外,您可以使用-volumes-from
可以将日志目录安装在一个实际上不运行任何应用程序的容器中,然后在其他容器中使用该容器中的卷,而不必在各处重复路径。
Additionally you can use --volumes-from
to mount your log directory in one container not actually running any application and then use the volumes from this container in your other containers without having to repeat the paths everywhere.
值得阅读 Docker卷
这篇关于我可以将同一卷安装到多个Docker容器吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!