How to expose volume in container using Dockerfile

i can create a container to expose the containter filesystem to the docker engine.
following is the command used.

docker run -it -v /home/kuenn/myDOCKER/myfile03az/mydata:/mydata debian /bin/bash

however, i will like to express this in the Dockerfile instead of running from command syntax.

Hi,

You wont be able to mount a directory as volume from host to container in Dockerfile. The VOLUME instruction in Dockerfile just creates the specified mount point as mark it as a location to hold volume.

If you want to move this out from the command line and want it to be expressed in some sort of file, just have a look at Docker Compose. In Docker compose you can actually express the containers and their various options that should be passed to them.

This will help you in understanding more about compose and volumes https://docs.docker.com/compose/yml/#volumes

Regards

1 Like