Bunyk
Bunyk

Reputation: 8067

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?

Upvotes: 3

Views: 393

Answers (1)

Adrian Mouat
Adrian Mouat

Reputation: 46500

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.

Upvotes: 2

Related Questions