title: docker-compose: execute database scripts
body: <p>I am setting up a local mssql database using docker-compose and a dockerfile.</p>
  
  <p>I was able to use the example here:</p>
  
  <pre><code>https://github.com/mcmoe/mssqldocker
  </code></pre>
  
  <p>which executes a database script to create the database upon startup. I am now running a couple of sql scripts to setup the database.</p>
  
  <p>So I can run:</p>
  
  <pre><code>docker-compose build
  </code></pre>
  
  <p>then...</p>
  
  <pre><code>docker-compose up
  </code></pre>
  
  <p>And docker will start mssql and run the scripts to create my database, schemas with tables, views and pre-populated data.</p>
  
  <p>However, if I run:</p>
  
  <pre><code>docker-compose stop
  </code></pre>
  
  <p>then run:</p>
  
  <pre><code>docker-compose up
  </code></pre>
  
  <p>It tries to run all the scripts <em>again</em> which is not good (lots of errors).
  Ideally I only ever want this to happen once.  Is there a way to tell docker not to run the scripts if they have already been ran?</p>
  
  <p>I really want to reduce setup of a local db to really one thing:</p>
  
  <p><code>docker-compose up</code> - should do everything.</p>
  
  <p>EDIT:</p>
  
  <p>I tried wrapping the SQL scripts using:</p>
  
  <pre><code>if [ ! -d "/var/lib/mssql/data" ]; then 
    # scripts in here
  fi
  </code></pre>
  
  <p>but it always skips over them!</p>