title: Deploy SQL Server with pre-installed DB using Docker
body: <p>I have created a docker image of SQL Server that includes a restored backup of an empty DB using the following dockerfile:</p>
  <pre><code>FROM mcr.microsoft.com/mssql/server:2019-latest AS build
  ENV ACCEPT_EULA=Y
  ENV SA_PASSWORD=myP@ss0rd#
  ENV MSSQL_PID=Express
  
  # Have a stage specifically to populate the data directory
  FROM build AS data
  WORKDIR /tmp
  COPY TiPS_v.1.3.4.0.bak .
  COPY restore-backup.sql .
  
  RUN /opt/mssql/bin/sqlservr --accept-eula &amp; sleep 10 \
      &amp;&amp; /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P &quot;myP@ss0rd#&quot; -i /tmp/restore-backup.sql \
      &amp;&amp; pkill sqlservr
  
  # Final stage that actually will actually be run.   
  FROM build AS release
  # Copy the prepopulated data tree, but not the backup file
  COPY --from=data /var/opt/mssql/data /var/opt/mssql/data    
  </code></pre>
  <p>Running a docker container off of that image works fine and I can access the restored DB. But when I try to run using docker-compose with following yml file:</p>
  <pre><code>version: '3'
  services:
    mssql:
      image: tips-db:1.3.4.1
      container_name: &quot;mssql-tips&quot;
      user: root
      restart: always
      environment:
        ACCEPT_EULA: Y
      volumes:
        - ./mssql/data/:/var/opt/mssql/data
        - ./mssql/log/:/var/opt/mssql/log
        - ./mssql/secrets/:/var/opt/mssql/secrets   
      ports:
        - 11433:1433 
  </code></pre>
  <p>the restored DB is not there anymore. Only system databases are present.</p>
  <p>I have only basic understanding of docker. I really can't understand why the .mdf, .ldf files of my Db are not persisted when then container is run. I can only see the files from system databases inside my local <code>mssql/data</code> folder.</p>
  <p>Is there something I could do so that my restored DB is persisted after the container is run through docker-compose?</p>