title: Symlink to volume in Docker container
body: <p>I've created a Docker container a small application, in which I have a directory whose contents I want to replace (or not) depending on the environment. I'm trying to solve this by creating a volume and only mounting it in other environments. Inside the container, I'm creating a symlink to the volume from my source directory.</p>
  
  <pre><code>FROM php:5.6-apache
  
  # Copy in sources files etc
  # Ensure the directory exists and make a symlink to it
  RUN mkdir -p /data/share \
      &amp;&amp; rm -rf /app/src/dir \
      &amp;&amp; ln -s /data/share /app/src/dir \
      &amp;&amp; chown -hR appropriate:settings /app/src/dir
  
  VOLUME ["/data/share"]
  </code></pre>
  
  <p>When I run the container in development, I simply don't mount anything on <code>/data/share</code>, and in production I mount a directory from the host (which is in turn a mounted S3 directory, in case that makes a difference).</p>
  
  <p>I'm finding that the <code>/data/share</code> directory is being correctly mounted, however my symlink simply fails to be established. Running <code>docker exec -it &lt;container_id&gt; ls -la /app/src/</code> does not show the directory as a symlink, nor does going inside the container by running bash and inspecting the directory. Creating the symlink by hand after the container has started is fine.</p>
  
  <p>Do I need to do something different when creating symlinks during a container build and/or run?</p>
  
  <p><strong>Update with specifics</strong></p>
  
  <p>I'm attempting to mount a directory from the host (a mounted S3 bucket) in the container <em>only in production</em>, because I don't need it in dev &amp; staging but I do need it to persist between containers and machines (I'm deploying through AWS Elastic Beanstalk) in production.</p>
  
  <p>I've tried mounting the host directory directly on to <code>/app/src/dir/</code>, but I found I wasn't able to change the owner and group of the directory to allow the application to read from it (the web server doesn't run as root).</p>