Pankaj Jangid
Pankaj Jangid

Reputation: 612

docker run -v works even without VOLUME or mkdir

What is the use of "VOLUME" or "RUN mkdir /m"?

Even if I do not specify any of these instructions in the Dockerfile, then also "docker run -v ${PWD}/m:/m" works.

Upvotes: 1

Views: 954

Answers (1)

mkasberg
mkasberg

Reputation: 17312

Inside a Dockerfile, VOLUME marks a directory as a mount point for an external volume. Even if the docker run command doesn't mount an existing folder into that mount point, docker will create a named volume to hold the data.

RUN mkdir /m does what mkdir does on any Unix system. It makes a directory named m at the root of the filesystem.

docker run -v ... binds a host directory to a volume inside a container. It will work whether or not the mount point was declared as a volume in a Dockerfile, and it will also create the directory if it doesn't exist. So neither VOLUME or RUN mkdir are specifically necessary before using that command, though they may be helpful to communicate the intent to the user.

Upvotes: 1

Related Questions