Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I specify host directory to mount from Dockerfile

Tags:

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?

like image 917
Slartibartfast Avatar asked Sep 18 '13 13:09

Slartibartfast


People also ask

How do I change the directory in Dockerfile?

Easy ! Just use the WORKDIR command to change the directory you want to. Any other commands you use beyond this command will be executed in the directory you have set. It is also a better practice to make use of WORKDIR in docker.


1 Answers

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.

like image 99
creack Avatar answered Nov 05 '22 18:11

creack