MathieuAuclair MathieuAuclair - 8 months ago 103
Linux Question

Docker: launch a mssql script outside of the docker image

I've been trying to run an MSSQL script on my docker and it always fails... is my syntax wrong or something... I've looked this post but it doesn't work
Executing SQL scripts on docker container

docker exec mssql '/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P gitgood12345 -q </CRE.sql'

this returned an error

rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:262: starting container process caused "exec: \"/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ************** -q </CRE.sql\": stat /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P AucMa1633485 -q </CRE.sql: no such file or directory"

I also tried something like this...

sudo docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'gitgood12345' -q </CRE.sql

The command returns me this error, which I'm not sure why....

Sqlcmd: '-q': Missing argument. Enter '-?' for help.

Please help me... the second method used to work, I think I forget a parameter or something...

Answer Source

The sqlcmd -q option requires an argument of the command you want to run. As your example is piping commands in on standard input, try without the -q.

docker exec mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P gitgood12345 < /CRE.sql

Quoting everything results in the container trying to execute a binary named /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P gitgood12345 -q </CRE.sql which doesn't exist.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download