title: Docker: How to run a sql script in SQL Server Dockerfile
body: <p>I am trying to build a SQL Server container and then run some SQL scripts to add a user and make the schema by using <code>docker build .</code> and later <code>docker-compose build</code> -> <code>docker-compose up</code></p>
  
  <pre><code>FROM mcr.microsoft.com/mssql/server
  COPY all.sql all.sql
  COPY auto-setup-db.sql auto-setup-db.sql
  
  RUN /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P myPassword -i auto-setup-db.sql
  </code></pre>
  
  <p>this line^ fails with: </p>
  
  <blockquote>
    <p>Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.<br>
    Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.<br>
    Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..  </p>
    
    <p>The command '/bin/sh -c /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P myPassword -i auto-setup-db.sql' returned a non-zero code: 1</p>
  </blockquote>
  
  <p>And I'm not sure what I'm doing wrong, does anyone have an idea?</p>
  
  <p>EDIT: this is the relevant part of my docker-compose file:</p>
  
  <pre><code>version: '3'
  services:
    mssql:
      image: mssql
      build: ./e2e/mssql
      container_name: mssql
      environment:
        SA_PASSWORD: "myPassword"
        ACCEPT_EULA: "Y"
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <p>Running <code>docker-compose up</code> gives a lot of output from SQL Server ex. </p>
  
  <pre><code>2019-08-29 17:05:13.02 spid8s      Starting up database 'tempdb'.
  </code></pre>
  
  <p>but I need to find a way to run the schema script in there so I thought docker-build would be the easiest place. I'm very new to docker</p>