title: Docker Compose Sql server Creating a database and tables automatically upon startup
body: <p>I created a asp.net core web api with Sql server.
  By running docker compose file I need to create a database and tables.
  My solutions is as follows</p>
  
  <p><strong>Dockerfile</strong></p>
  
  <pre><code>FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
  WORKDIR /app
  EXPOSE 80
  
  FROM microsoft/dotnet:2.2-sdk AS build
  WORKDIR /src
  COPY StarterPackMSSQL.StarterPackMSSQL.csproj StarterPackMSSQL/
  RUN dotnet restore StarterPackMSSQL/StarterPackMSSQL.csproj
  COPY . .
  WORKDIR /src/StarterPackMSSQL
  RUN dotnet build StarterPackMSSQL.csproj -c Release -o /app
  
  FROM build AS publish
  RUN dotnet publish StarterPackMSSQL.csproj -c Release -o /app
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app .
  ENTRYPOINT ["dotnet", "StarterPackMSSQL.dll"]
  </code></pre>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre><code>version: '3.5'
  
  networks : 
    localdev:
      name: localdev
  
  services:
   starterpackmssql:
      image: ${DOCKER_REGISTRY-}mssql
      restart: always
      build:
        context: .
        dockerfile:StarterPackMSSQL/Dockerfile
      ports:
        - "5001:80"
      depends_on:
        - db-server
      networks:
        - localdev
  
    db-server:
      image: microsoft/mssql-server-linux
      container_name: db-server
      environment:
        - ACCEPT_EULA=Y
        - MSSQL_SA_PASSWORD=password123
        - MSSQL_TCP_PORT=1433
  
      ports:
        - "1400:1433"
      networks:
        - localdev
  </code></pre>
  
  <p><strong>SQL Script</strong></p>
  
  <pre><code>CREATE DATABASE [StarterPacksDB]
  GO
  
  USE [StarterPacksDB]
  GO
  
  /****** Object:  Table [dbo].[Users]    Script Date: 10/18/2019 10:42:39 PM ******/
  SET ANSI_NULLS ON
  GO
  
  SET QUOTED_IDENTIFIER ON
  GO
  
  CREATE TABLE [dbo].[User](
      [id] [int] IDENTITY(1,1) NOT NULL,
      [handle] [varchar](50) NOT NULL,
   CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
  (
      [id] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  GO
  </code></pre>
  
  <p>I just need to create database and tables automatically upon when running <code>docker-compose up</code></p>
  
  <p>And it should work on both mac and windows.</p>