Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

dockerfile - Can I mount same volume to multiple docker containers

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes you can add same location as a volume to many docker containers.

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.

Worth a read Docker volumes


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...