Skip to content

Instantly share code, notes, and snippets.

@theoretick
Last active September 28, 2018 16:56
Show Gist options
  • Save theoretick/6da1c84d06b6cffdfbd055b06fd41d96 to your computer and use it in GitHub Desktop.
Save theoretick/6da1c84d06b6cffdfbd055b06fd41d96 to your computer and use it in GitHub Desktop.
Running dockerized MSSQL on MacOS

Pull Docker image for SQL Server 2017

❯ docker pull mcr.microsoft.com/mssql/server:2017-latest
Password:
2017-latest: Pulling from mssql/server
f6fa9a861b90: Pull complete
5ad56d5fc149: Pull complete
170e558760e8: Pull complete
395460e233f5: Pull complete
6f01dc62e444: Pull complete
3a52205d40a6: Pull complete
6192691706e8: Pull complete
876584dea625: Pull complete
49e9c80a6fa9: Pull complete
3e6f1aaa79f4: Pull complete
Digest: sha256:1bbf3b11687ce4d97eb5e6b6e61ccc500d0eff92f92e51893112a3fc665ce7b7
Status: Downloaded newer image for mcr.microsoft.com/mssql/server:2017-latest

Run it

❯ docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<Passw0rd!>' \
    -p 1433:1433 --name sql1 \
    -d mcr.microsoft.com/mssql/server:2017-latest
dd9e02b0eca5670bc45cd91a3146ab79d53b5008fd1c830813cee33c1d3cb6d4

Connect

❯ docker exec -it sql1 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '<Passw0rd!>'
1> SELECT Name from sys.Databases
2> GO
Name
--------------------------------------------------------------------------------------------------------------------------------
master
tempdb
model
msdb

Create some stuff

(4 rows affected)
1> CREATE DATABASE TestDB
2> USE TestDB
3> CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity  INT)
4> INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
5> GO
Changed database context to 'TestDB'.

(1 rows affected)

(1 rows affected)
1> SELECT * FROM Inventory WHERE quantity > 152;
2> GO
id          name                                               quantity
----------- -------------------------------------------------- -----------
          2 orange                                                     154

(1 rows affected)
1> SELECT * FROM Inventory where quantity > 152;
2> GO
id          name                                               quantity
----------- -------------------------------------------------- -----------
          2 orange                                                     154

(1 rows affected)
1> QUIT
root@dd9e02b0eca5:/# exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment