My goal is to create an SQL login for my apps before running other images. Since my container uses Linux - scripts are saved with LF line endings. And the Docker output console is not showing any errors related to the script, only about my apps - they can't connect to the server because no such login exists.
The problem is that the shell script is not running and no login is being created. Thanks for your help in advance.
I was looking for the examples on the web, and here is what I came up with:
docker-compose.yml
version: '3.4'
services:
mssql:
image: mcr.microsoft.com/mssql/server:2019-latest
environment:
SA_PASSWORD: "3qqimIuTQEGqVCD!"
ACCEPT_EULA: "Y"
LOGIN: "MyLogin"
PASSWORD: "3qqimIuTQEGqVCD!"
ports:
- "1433:1433"
volumes:
- ./DockerScripts/SQL/CreateLogin.sql:/CreateLogin.sql
- ./DockerScripts/Shell/Entrypoint.sh:/Entrypoint.sh
entrypoint:
- ./Entrypoint.sh
webapi:
image: ${DOCKER_REGISTRY-}webapi
build:
context: .
dockerfile: Source/Code/Web/WebApi/Dockerfile
depends_on:
- mssql
maintenance:
image: ${DOCKER_REGISTRY-}maintenance
build:
context: .
dockerfile: Source/Code/Web/Maintenance/Dockerfile
depends_on:
- mssql
DockerScripts\Shell\Entrypoint.sh
#!/bin/bash
# Start SQL server
/opt/mssql/bin/sqlservr
# Wait for MSSQL server to start
export STATUS=1
i=0
while [[ $STATUS -ne 0 ]] && [[ $i -lt 30 ]]; do
i=$i+1
/opt/mssql-tools/bin/sqlcmd -t 1 -U sa -P $SA_PASSWORD -Q "select 1" >> /dev/null
STATUS=$?
done
if [ $STATUS -ne 0 ]; then
echo "Error: MS SQL Server took more than 30 seconds to start up."
exit 1
fi
echo "MS SQL Server started successfully."
echo "Setting up server login."
/opt/mssql-tools/bin/sqlcmd -U sa -P $SA_PASSWORD -S localhost -i CreateLogin.sql
DockerScripts\SQL\CreateLogin.sql
USE [master];
GO
CREATE LOGIN [$(LOGIN)] WITH PASSWORD=N'$(PASSWORD)', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF;
GO
ALTER SERVER ROLE [dbcreator] ADD MEMBER [$(LOGIN)];
GO
UPDATE
I removed a lot of stuff since it doesn't relate to the issue.
So for now, the main problem persists - Entrypoint.sh just not being called on compose startup.
sleepthere.