How to create a volume from a local path in a Dockerfile?

With command line arguments, I can indicate that I want to mount a local directory as a volume:

docker run -i -t -v /path/to/directory/:/mount/point testimage

However, I can’t find anything to describe the syntax to VOLUME in a Dockerfile to do the same thing. Can anyone explain what this looks like?

  • How do we get something unique like pod id or container id in kubernetes deployment yamls
  • “ImportError: No module named _bsddb” when opening shelve in Docker container
  • Docker Use LXC with Direct Host Networking
  • How to prevent docker containers from consuming all CPU?
  • Docker out of disk space on aufs although df shows plenty
  • Installing github hosted npm dependencies with Docker
  • How to have docker restart container with a completely new container?
  • Lumen: PHPUnit give failure but testing passed in Gitlab CI Runner
  • How to build docker images with volumes for production
  • brief overview of current docker workflow with nginx
  • Error running docker container: No space left on device: “/data/db/journal”
  • Docker: cannot use postgres client connect to database container
  • One Solution collect form web for “How to create a volume from a local path in a Dockerfile?”

    Dockerfiles only define the right side (which paths within the container are volumes) — not the local/left side.

    The mapping is done during container creation, not image creation.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.