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
1.3k views
in Technique[技术] by (71.8m points)

docker - Can I specify host directory to mount from Dockerfile

Docker run command has option to mount host directory into container

-v=[]: Create a bind mount with: [host-dir]:[container-dir]:[rw|ro]. 
       If "host-dir" is missing, then docker creates a new volume.

And Dockerfile has VOLUME instruction

VOLUME ["/data"] - The VOLUME instruction will add one or more new volumes 
                   to any container created from the image.

From what I see, there is no way to specify host-dir or rw/ro status when using Dockerfile.

Is there any other use of VOLUME in docker file other than wanting to share it with some other container?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Dockerfiles are meant to be portable and shared. The host-dir volume is something 100% host dependent and will break on any other machine, which is a little bit off the Docker idea.

Because of this, it is only possible to use portable instructions within a Dockerfile. If you need a host-dir volume, you need to specify it at run-time.

A common usage of VOLUME from Dockerfile is to store configuration or website sources so that it can be updated later by another container.


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

1.4m articles

1.4m replys

5 comments

57.0k users

...