1

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 docker build . and later docker-compose build -> docker-compose up

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

this line^ fails with:

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
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..

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

And I'm not sure what I'm doing wrong, does anyone have an idea?

EDIT: this is the relevant part of my docker-compose file:

version: '3'
services:
  mssql:
    image: mssql
    build: ./e2e/mssql
    container_name: mssql
    environment:
      SA_PASSWORD: "myPassword"
      ACCEPT_EULA: "Y"

EDIT 2:

Running docker-compose up gives a lot of output from SQL Server ex.

2019-08-29 17:05:13.02 spid8s      Starting up database 'tempdb'.

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

6
  • 1
    Where in your code are you creating the instance? The Microsoft docs have the script where you need to accept the EULA, set the SA password, etc. Commented Aug 29, 2019 at 16:41
  • @dfundako I try to pass it in like this (see edit) and get the same error Commented Aug 29, 2019 at 16:52
  • Should the Y be quoted in the environment variable? Commented Aug 29, 2019 at 16:55
  • @dfundako yes (docs.docker.com/compose/aspnet-mssql-compose) but my password should be too, good catch, will report back. EDIT: same error Commented Aug 29, 2019 at 16:56
  • 1
    Similar question Docker + mssql-server-linux: How to launch .sql file during build (from Dockerfile). As @Daniel N suggested, the server might not be running when the sqlcmd is executed Commented Aug 30, 2019 at 6:13

1 Answer 1

0

Trying adding double quotes around the file path and use the full path. Please see the example.

. . . EXPOSE 1433

RUN mkdir -p /var/opt/mssql/database

WORKDIR /var/opt/mssql/database

COPY auto-setup-db.sql .

CMD /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P myPassword -i "/var/opt/mssql/database/auto-setup-db.sql" -o "/var/opt/mssql/database/auto-setup-db.log"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.