2

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...

MathieuAuclair
  • 1,229
  • 11
  • 41
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Oct 03 '17 at 14:32

1 Answers1

4

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.

Matt
  • 68,711
  • 7
  • 155
  • 158