Run go-sqlcmd in a Docker container
294
This Repository provides the sqlcmd (Go) command line tool by Microsoft (https://github.com/microsoft/go-sqlcmd) as a docker image.
See the Github Repo here for more Info, as this here might be outdated!
Similar to mcr.microsoft.com/mssql-tools, only that it doesn't use bash, but sh as the default shell.
docker pull bastisk/go-sqlcmd:latest
docker run -it bastisk/go-sqlcmd:latest
~ $ sqlcmd
This might be the most common use case, automatically applying a sql script to a given database from within Docker!
Check out this directory for an example implementation.
a) script.sql
SELECT * FROM TABLE;
b) script.sh
sqlcmd -S <srv> -d <db> --authentication-method ActiveDirectoryServicePrincipal -U "<clientid>@<tenantid>" -P <pw> -i /script.sql
FROM bastisk/go-sqlcmd:latest
COPY script.sh /script.sh
COPY script.sql /script.sql
CMD ["bash", "/script.sh"]
Run a command using a kubernetes job, see this example.
TL;DR: take a look here for the yaml!
apiVersion: apps/v1
kind: Deployment
metadata:
name: sqltools-debugger
spec:
selector:
matchLabels:
app: sqltools
replicas: 1
template:
metadata:
labels:
app: sqltools
spec:
containers:
- name: sqltools
image: bastisk/go-sqlcmd:latest
command: [ "/bin/sh", "-c", "--" ]
args: [ "while true; do sleep 30; done;" ]
restartPolicy: Never
sh in the pod and do stuff with sqlcmd, for example like so:> kubectly apply -f sqltools.yaml # this is the yaml above
deployment.apps/sqltools-debugger created
> kubectl get pods
NAME READY STATUS RESTARTS AGE
smartspacesingress-6cfb685555-gmsw8 1/1 Running 0 84m
> kubectl exec -it sqltools-debugger-6d6f6f5d88-xvp56 -- sh
~ $ sqlcmd -S <server> -d <db> -U <principalId>@<tenantId> -P <password> --authentication-method ActiveDirectoryServicePrincipal
> kubectl delete -f sqltools.yaml
deployment.apps "sqltools-debugger" deleted
Content type
Image
Digest
sha256:1b7b654a2…
Size
60.3 MB
Last updated
over 2 years ago
docker pull bastisk/go-sqlcmd