SQL Server Git Bash SQLCmd "Error response from daemon: No such container"

uxhixvfz  于 12个月前  发布在  Git
关注(0)|答案(1)|浏览(147)

I am trying to install the a sample database in a docker container, using a Git Bash script file. This is on my Windows 10 development machine.
Yet when I try to execute a simple SQL query using 'git bash', I am getting the error

Error response from daemon: No such container: sqladventureworks /opt/mssql-tools/bin/sqlcmd

What am I doing wrong in my script file?

If I connect to the database using SSMS, the database behaves as expected.

Contents of MyScript.sh

!/bin/bash  
#   

SA_PASSWORD=MyStrongPassword4$  
CONTAINER_NAME=sqladventureworks  
LOCAL_BACKUP_FOLDER="$(PWD)/backup"  
TARGET_DB_NAME="AdventureWorks"  

mkdir $LOCAL_BACKUP_FOLDER
clear  
echo "Download AdventureWorks Lite backup file"
curl -L -o $LOCAL_BACKUP_FOLDER/AdventureWorksLT2022.bak 'https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorksLT2022.bak'

echo "Pull latest MS-SQL image"  
docker pull mcr.microsoft.com/mssql/server
  
###  
echo "Delete existing containers"  
docker stop $CONTAINER_NAME || true && docker rm $CONTAINER_NAME || true
###  

echo "Create & Start container"  
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=$SA_PASSWORD" \
   -e 'TZ= Europe/London' \
   -p 1433:1433 --name $CONTAINER_NAME --hostname $CONTAINER_NAME \
   --mount type=bind,source=$LOCAL_BACKUP_FOLDER,target=/var/opt/mssql/backup \
   -d \
   mcr.microsoft.com/mssql/server
###

echo "Wait 9 seconds for MS-SQL server to start"  
sleep 9

echo "List containers"  
docker container ls
   echo "-----------------------------------------------"
   echo "-----------------------------------------------"   

echo "Execute SQL query"  
 winpty docker exec -it "$CONTAINER_NAME /opt/mssql-tools/bin" \
    -S localhost -U SA \
   -Q "select 'Ping Pong' as [DummyText]"
   
#
   
read -p "Press enter to close"
kpbwa7wx

kpbwa7wx1#

When I run the docker SQL query command directly in git bash, it works as expected.
However when I run it as part of a bash script file, I get even more errors.
So as I do not want to spend any more time on this, I am going to have to tackle this in a multistep way.

相关问题