Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile VOLUME definition to mount project tree

I'm trying to automate creation of dev environment and deployment using Docker. Here is my minimal example of my Dockerfile:

FROM java
VOLUME .:/hello

and build it as

docker build -t hello-server .

Then i run image hello-server, visit it's /hello directory, it exists, but is empty.

But when I run image using

docker run -i -t -v $(pwd):/hello2 hello-server

/hello2 contains README, Dockerfile and other files of the project. How to properly define volume mounting from Dockerfile?

like image 851
Bunyk Avatar asked Dec 14 '25 08:12

Bunyk


1 Answers

This doesn't work:

VOLUME .:/hello

You can't specify the host directory for a volume in a Dockerfile. The reason is that it would be non-portable.

Either copy the files into the image with COPY or just mount the volume at run-time as you have been doing.

like image 156
Adrian Mouat Avatar answered Dec 16 '25 23:12

Adrian Mouat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!