title: Mount directory in Container and share with Host
body: <p>I thought I understood the docs, but maybe I didn't. I was under the impression that the <code>-v /HOST/PATH:/CONTAINER/PATH</code> flag is bi-directional. If we have file or directories in the container, they would be mirrored on the host giving us a way to retain the directories and files even after removing a docker container.</p>
  
  <p>In the official MySQL docker images, this works. The <code>/var/lib/mysql</code> can be bound to the host and survive restarts and replacement of container while maintaining the data on the host.</p>
  
  <p>I wrote a docker file for sphinxsearch-2.2.9 just as a practice and for the sake of learning and understanding, here it is:</p>
  
  <pre><code>FROM debian
  
  ENV SPHINX_VERSION=2.2.9-release
  
  RUN apt-get update -qq &amp;&amp; DEBIAN_FRONTEND=noninteractive apt-get install -yqq\
      build-essential\
      wget\
      curl\
      mysql-client\
      libmysql++-dev\
      libmysqlclient15-dev\
      checkinstall
  
  RUN wget http://sphinxsearch.com/files/sphinx-${SPHINX_VERSION}.tar.gz &amp;&amp; tar xzvf sphinx-${SPHINX_VERSION}.tar.gz &amp;&amp; rm sphinx-${SPHINX_VERSION}.tar.gz
  
  RUN cd sphinx-${SPHINX_VERSION} &amp;&amp; ./configure --prefix=/usr/local/sphinx
  
  EXPOSE 9306 9312
  
  RUN cd sphinx-${SPHINX_VERSION} &amp;&amp; make
  
  RUN cd sphinx-${SPHINX_VERSION} &amp;&amp; make install
  
  RUN rm -rf sphinx-${SPHINX_VERSION}
  
  VOLUME /usr/local/sphinx/etc
  VOLUME /usr/local/sphinx/var
  </code></pre>
  
  <p>Very simple and easy to get your head wrapped around while learning. I am assigning the /etc &amp; /var directories from the sphinx build to the VOLUME command thinking that it will allow me to do something like <code>-v ~/dev/sphinx/etc:/usr/local/sphinx/etc -v ~/dev/sphinx/var:/usr/local/sphinx/var</code>, but it's not, instead it's overwriting the directories inside the container and leaving them blank. When i remove the -v flags and create the container, the directories have the expected files and they are not overwritten.</p>
  
  <p>This is what I run to create the docker file after navigating to the directory that it's in: <code>docker build -t sphinxsearch .</code></p>
  
  <p>And once I have that created, I do the following to create a container based on that image: <code>docker run -it --hostname some-sphinx --name some-sphinx --volume ~/dev/docker/some-sphinx/etc:/usr/local/sphinx/etc -d sphinxsearch</code></p>
  
  <p>I really would appreciate any help and insight on how to get this to work. I looked at the MySQL images and don't see anything magical that they did to make the directory bindable, they used VOLUME.</p>
  
  <p>Thank you in advance.</p>