我可以将相同的卷挂载到多个 docker 容器吗 [英] Can I mount same volume to multiple docker containers

查看:48
本文介绍了我可以将相同的卷挂载到多个 docker 容器吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将应用程序日志共享到挂载的卷.我想将相同的卷安装到所有 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆