Dockerfile VOLUME not working

I am really stuck with the usage of docker VOLUME’s. I have a plain dockerfile:

FROM ubuntu:latest  
VOLUME /foo/bar
RUN touch /foo/bar/tmp.txt

I ran $ docker build -f dockerfile -t test . and it was successful. After this, I interactively ran a shell into the docker container associated with the run of the created test image. That is, I ran $ docker run -it test

  • Is there a way to backup my docker environment
  • Vagrant with Docker provider does not share folders
  • Set local network IP placeholder in docker-compose.yml
  • Illegal tokens added after modifying the file inside data volume
  • Private docker registry and high availability
  • Docker container A dies after excuting query(insert/update) in cassandra running as another docker service B
  • Observations:

    /foo/bar is created but empty.

    docker inspect test mounting info:

    "Volumes": {
      "/foo/bar": {}

    It seems that it is not mounting at all. The task seems pretty straight but am I doing something wrong ?

    EDIT : I am looking to persist the data that is created inside this mounted volume directory.

  • What's a sane way to define custom travis job?
  • How to quickly switch between docker environments for development?
  • Installing mongoimport in a docker image
  • FATA[0000] Cannot connect to the Docker daemon. Is 'docker -d' running on this host?
  • Two containers - two Pythons - one site-packages?
  • ASP.NET exceptions in AWS Linux
  • One Solution collect form web for “Dockerfile VOLUME not working”

    The VOLUME instruction must be placed after the RUN.

    As stated in :

    Note: If any build steps change the data within the volume after it has been declared, those changes will be discarded.

    If you want to know the source of the volume created by the docker run command:

    docker inspect --format='{{json .Mounts}}' yourcontainer

    will give output like this:

      "Name": "4c6588293d9ced49d60366845fdbf44fac20721373a50a1b10299910056b2628",
      "Source": "/var/lib/docker/volumes/4c6588293d9ced49d60366845fdbf44fac20721373a50a1b10299910056b2628/_data",
      "Destination": "/foo/bar",
      "Driver": "local",
      "Mode": "",
      "RW": true,
      "Propagation": ""

    Source contains the path you are looking for.

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