title: How to prevent database docker from being rebuilt and losing production data
body: <p>I love using docker &amp; docker-compose for both development and production environments.</p>
  
  <p>But in my workflow, I keep considering dockers as <strong>disposable</strong>:</p>
  
  <p>it means if I need to add a feature to my docker, I edit my <code>Dockerfile</code>, then run <code>docker-compose build</code> and <code>docker-compose up -d</code> and done.</p>
  
  <p>But this time, the production DB is also in a Docker. </p>
  
  <p>I still need to make some changes in my environment (eg. configuring backup), but now I can't rerun <code>docker-compose build</code> because this would imply a <strong>loss of all the data</strong>... It means I need to enter the docker (<code>docker-compose run web /bin/bash</code>) and run the commands inside it while still reporting those to my local <code>Dockerfile</code> to keep track of my changes.</p>
  
  <p>Are there any best practices regarding this situation?</p>
  
  <p>I thought of setting up a process that would dump the DB to a S3 bucket before container destruction, but it doesn't really scale to wide DBs... </p>
  
  <p>I thought of making a Docker not destructible (how?), though it means losing the disposability of a container.</p>
  
  <p>I thought of having a special partition that would be in charge of storing the data <strong>only</strong> and that would not get destructed when rebuilding the docker, though it feels hard to setup and unsecure.</p>
  
  <p>So what? </p>
  
  <p>Thanks</p>