Mssql-docker: Linux Container - Running SQL script file using sqlcmd in a shell script fails

Created on 14 May 2018  路  5Comments  路  Source: microsoft/mssql-docker

I've been trying to run a SQL script on build time of container. I have a shell script that looks something like this:
echo "Starting SqlServr"
/opt/mssql/bin/sqlservr &
sleep 30 | echo "Waiting for 30s to start Sql Server"
echo "Restoring DB."
/opt/mssql-tools/bin/sqlcmd -U sa -P <valid-password> -i RestoreDb.sql
echo "DB restored."
echo "Deleting backup files."
rm -rf /work/*.bak

I run this from Dockerfile using: RUN

I'm getting error ': Invalid filename.ql

When I run the same command from shell /opt/mssql-tools/bin/sqlcmd -U sa -P <valid-password> -i RestoreDb.sql it works perfectly fine.
Also when I replace -i RestoreDb.sql to -Q <file-content> it also works perfectly fine.

Looks like something to do with sqlcmd and bash.

Most helpful comment

Check EOL character. It needs to be set to LF only since container runs linux.

All 5 comments

Can you please share your Dockerfile, .sh script, and .sql script (redacting anything sensitive)?

Here's the repo: mssql-linux-container-test

I've tried again making some changes.
It worked on Linux container on Linux machine.
But did not work on Linux container on Windows machine.

Also there are chances of inconsistent line ending. I've seen \r at the end of line in shell script when I edit on windows machine. This maybe the issue.

image

Check EOL character. It needs to be set to LF only since container runs linux.

yes. did it. But, this will be the issue when created scripts on windows dev machine.
And main problem is with the error message, it doesn't provide correct information on what went wrong.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KristianFenn picture KristianFenn  路  5Comments

richmccloud picture richmccloud  路  3Comments

Ducatel picture Ducatel  路  4Comments

superbobdthm picture superbobdthm  路  7Comments

andyjansson picture andyjansson  路  3Comments