1 min readJul 16, 2019
Use docker cp
to copy your files into the running container instance. From there, you should be able to docker exec sql bash
to give you a prompt inside the container instance, or you can run the command directly.
docker cp YOURFILE sqlcontainername:/tmp/YOURFILE
docker exec sqlcontainername \
/opt/mssql-tools/bin/sqlcmd \
-j -I -S localhost -U sa -P "YOURSAPASS" \
-i /tmp/YOURFILE
docker exec sqlcontainername rm /tmp/YOURFILE
Your command may not be sqlcmd, but the above should point you or anyone seeing this in the right direction.
I automate using node/npm scripts with shelljs
, there’s also a docker-cli-js
package.
// copies and runs a local sql script file inside the
// docker container's instance
const runSqlScript = (scriptPath, container) => { console.log(`Running SQL Script (${scriptPath})`); // copy the local file into the container
shell.exec(`docker cp "${scriptPath}" ${container}:/tmp/temp.sql`); // execute the file in the container on sql
shell.exec(
`docker exec -i ${container}/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "Let_Me_In" -i /tmp/temp.sql -j -I`
); // remove the file inside the container
shell.exec(`docker exec ${container}rm /tmp/temp.sql`);
};