microsoft / mssql-docker

Official Microsoft repository for SQL Server in Docker resources
MIT License
1.71k stars 755 forks source link

Linux Container - Running SQL script file using sqlcmd in a shell script fails #308

Open iqan opened 6 years ago

iqan commented 6 years ago

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.

twright-msft commented 6 years ago

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

iqan commented 6 years ago

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.

iqan commented 6 years ago

image

fabiopucci commented 6 years ago

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

iqan commented 6 years ago

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.