title: How can I fix the permissions using docker on a bluemix volume?
body: <p>In a container, I am trying to start mysqld.</p>
  
  <p>I was able to create an image and push to the registry but when I want to start it, the <code>/var/lib/mysql</code> volume can't be initialized as I try to do a <code>chown mysql</code> on it and it is not allowed.</p>
  
  <p>I checked docker specific solutions but for now I couldn't make any work.</p>
  
  <p><strong>Is there a way to set the right permissions on a bind-mounted folder from bluemix?</strong> Or is the option <code>--volumes-from</code> supported, I can't seem to make it work.</p>
  
  <p>The only solution I can see right now is running mysqld as root, but I would rather not.</p>
  
  <h2>Try with mount-bind</h2>
  
  <ol>
  <li>created a volume on bluemix using <code>cf ic volume create database</code></li>
  <li><p>try to run <code>mysql_install_db</code> on my db container to initialize it's content</p>
  
  <pre><code>docker run --name init_vol -v database:/var/lib/mysql registry.ng.bluemix.net/&lt;namespace&gt;/&lt;image&gt;:&lt;tag&gt; mysql_install_db --user=mysql
  </code></pre></li>
  </ol>
  
  <p><code>mysql_install_db</code> is supposed to populate the <code>/var/lib/mysql</code> and set the rights to the owner set in the <code>--user</code> option, but I get:</p>
  
  <blockquote>
    <p>chown: changing ownership of '/var/lib/mysql': Permission denied.</p>
  </blockquote>
  
  <p>I also tried the above in different ways, using sudo or a script. I tried with <code>mysql_install_db --user=root</code>, which does setup my folder correctly, except it is owned by the root user, and I would rather keep mysql running as the mysql user.</p>
  
  <h2>Try with volumes-from data container</h2>
  
  <ol>
  <li><p>I create a data container with a volume <code>/var/lib/mysql</code></p>
  
  <pre><code>docker run --name db_data -v /var/lib/mysql registry.ng.bluemix.net/&lt;namespace&gt;/&lt;image&gt;:&lt;tag&gt; mysql_install_db --user=mysql
  </code></pre></li>
  <li><p>I run my db container with the option <code>--volumes-from</code></p>
  
  <pre><code>docker run --name db_srv --volumes-from=db_data registry.ng.bluemix.net/&lt;namespace&gt;/&lt;image&gt;:&lt;tag&gt; sh -c 'mysqld_safe &amp; tail -f /var/log/mysql.err'
  </code></pre></li>
  </ol>
  
  <p><code>docker inspect db_srv</code> shows:</p>
  
  <blockquote>
    <p>[{   "BluemixApp": null,   "Config": {
        ...,
        "WorkingDir": "",
        ...   }   ... }]</p>
  </blockquote>
  
  <p><code>cf ic logs db_srv</code> shows:</p>
  
  <blockquote>
    <p>150731 15:25:11 mysqld_safe Starting mysqld daemon with databases from
    /var/lib/mysql 150731 15:25:11 [Note] /usr/sbin/mysqld (mysqld
    5.5.44-0ubuntu0.14.04.1-log) starting as process 377 .. /usr/sbin/mysqld: File './mysql-bin.index' not found (Errcode: 13)
    150731 15:25:11 [ERROR] Aborting</p>
  </blockquote>
  
  <p>which is due to <code>--volumes-from</code> not being supported, and to data created in the first not staying in the second run.</p>