title: Docker-Compose SQL Server database persist data after host restart
body: <p>My Docker-Compose.yml:</p>
  
  <pre><code>version: "3"
  services:
   db:
    image: microsoft/mssql-server-linux:2017-CU8
    ports: 
      - 1433:1433
    deploy:
      mode: replicated
      replicas: 1 
    environment:
      - ACCEPT_EULA=Y
      - MSSQL_SA_PASSWORD=SuperStrongSqlAdminPassword)(*£)($£)
    volumes:
      - /home/mssql/:/var/opt/mssql/
      - /var/opt/mssql/data
  </code></pre>
  
  <p>As you can see I have a volume mapped to a directory on the host machine: /home/msqql:/var/opt/mssql/</p>
  
  <p>If I do: <code>docker stack deploy -c docker-compose.yml [stack name]</code>.</p>
  
  <p>The server starts and I can see data is written to the hosts directory: <code>/home/mssql/*</code>.</p>
  
  <p>I then connect to the server and create a database, tables and add some data.</p>
  
  <p>If I then kill the stack using <code>docker stack rm [stack name]</code>, or restart the host for maintenance reasons etc.</p>
  
  <p>When SQL Server starts up again, although the <code>/home/mssql/*</code> still contains the files created by the server initially, if I connect to the server the database/tables/data is gone. </p>
  
  <p>Do I have to re-attach the database when the server restarts somehow, or something else I'm missing maybe?</p>
  
  <p>Thanks</p>