I create my MSSQL database docker container with only docker-compose.yml file and setup.sql file. My .yml file looks like that:
version: "3.7" services: sql-server-db: container_name: sql-server-db image: mcr.microsoft.com/mssql/server:2019-latest ports: - "1433:1433" environment: SA_PASSWORD: "secret123new!" ACCEPT_EULA: "Y" volumes: - ./data/mssql:/scripts/ command: - /bin/bash - -c - | # Launch MSSQL and send to background /opt/mssql/bin/sqlservr & pid=$$! # Wait for it to be available echo "Waiting for MS SQL to be available ⏳" /opt/mssql-tools/bin/sqlcmd -l 30 -S localhost -h-1 -V1 -U sa -P secret123new! -Q "SET NOCOUNT ON SELECT "YAY WE ARE UP" , @@servername" is_up=$$? while [ $$is_up -ne 0 ] ; do echo -e $$(date) /opt/mssql-tools/bin/sqlcmd -l 30 -S localhost -h-1 -V1 -U sa -P secret123new! -Q "SET NOCOUNT ON SELECT "YAY WE ARE UP" , @@servername" is_up=$$? sleep 5 done # Run every script in /scripts # TODO set a flag so that this is only done once on creation, # and not every time the container runs for foo in /scripts/*.sql do /opt/mssql-tools/bin/sqlcmd -U sa -P secret123new! -l 30 -e -i $$foo done echo "All scripts have been executed. Waiting for MS SQL(pid $$pid) to terminate." # Wait on the sqlserver process wait $$pi
cmd error looks like that:
sql-server-db | 2021-07-21 06:53:54.63 spid11s The tempdb database has 1 data file(s).
2021-07-21 06:53:54.65 spid25s The Sqlcmd: ‘/scripts/*.sql’: Invalid filename.
sql-server-db | ServiAll scripts have been executed. Waiting for MS SQL(pid 8) to terminate.
sql-server-db | ce Broker endpoint is in disabled or stopped state.
What could be wrong with this ? my setup.sql file is in /scripts folder. I don t have another files. Should i replace some of the code or some $$ lines ? Please give me some tips how to start docker mssql database with startup file on windows without node.js 🙂 Have a nice day !
Source: Docker Questions