Docker - multiple volumes inside the dockerfile

Viewed 3005

I am trying to add multiple to VOLUME, but it doesn't seem to work as expected. Here is my docker file.

FROM maven:3.6.1-jdk-8 as maven-build

VOLUME /apps/demo/conf
VOLUME /apps/demo/docs
VOLUME /apps/demo/logs

After the docker image is created, I ran it. I don't see the file inside the docker filesystem that I created on the host machine under /apps/demo/conf.

I know I can pass it through the command line through 'docker run -v path:path, but I am wondering if there is a way to do it inside the Dockerfile.

2 Answers

VOLUME X in a Dockerfile doesn't mean mount X from the host system. All this is doing is telling Docker to persist data written to /apps/demo/conf from within the container in a host directory. You might do that if you wanted to persist some data across container restarts for instance. If you want to mount a host filesystem within the container, you must use run -v as you said.

Main purpose of volume is to persist the data of the container if it gets deleted somehow. If you want to COPY config , why don't you use COPY inside Dockerfile and keep ot there. You van COPY from different directories.

And as you have mentioned, if you still wanna mount it, use run -v

Related