LoginSignup
0
1

More than 3 years have passed since last update.

Docker で SQL Server 2019 をお試し

Posted at

新しい SQL Server 2019 GA が公開されていたので、下記の手順に従って、試してみた。
クイック スタート: Docker を使用して SQL Server コンテナー イメージを実行する

環境

SQL Server 2019 GA の image 取得

PowerShell
rex02 > docker pull mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04
2019-GA-ubuntu-16.04: Pulling from mssql/server
59ab41dd721a: Pull complete
57da90bec92c: Pull complete
06fe57530625: Pull complete
5a6315cba1ff: Pull complete
739f58768b3f: Pull complete
fd449e8d7345: Pull complete
51d0933375e5: Pull complete
64f21ba81504: Pull complete
55b6919c0cc6: Pull complete
Digest: sha256:c8fa22553ce421b0482febcafa712b29cbb933b0d97a8671686797b31cf157a9
Status: Downloaded newer image for mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04
mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04

rex02 > docker images
REPOSITORY                       TAG                    IMAGE ID            CREATED             SIZE
mcr.microsoft.com/mssql/server   2019-GA-ubuntu-16.04   76c7c66bff02        5 weeks ago         1.57GB

up

パスワードを簡単な文字列にすると、SQL Server がすぐに終了してしまう。

PowerShell
rex02 > docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong@Passw0rd>" \
-p 1433:1433 --name sql1 \
-d mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04
26514f40a04465ef651b56126ba995d68041052dc830d400f587f767cffc3f3b
rex02 > docker ps -a 
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS                    NAMES
26514f40a044        mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04   "/opt/mssql/bin/perm…"   4 seconds ago       Up 3 seconds        0.0.0.0:1433->1433/tcp   sql1

データの作成とクエリ

SQL Server のコマンド実行が、GO だったのを思い出すのにしばらくかかった。

PowerShell
rex02 > docker exec -it sql1 bash
mssql@26514f40a044:/$ /opt/mssql-tools/bin/sqlcmd -S localhost -U SA
Password:
1> CREATE DATABASE TestDB
2> go

1> SELECT Name from sys.Databases
2> go
Name
--------------------------------------------------------------------------------------------------------------------------------
master
tempdb
model
msdb
TestDB

(5 rows affected)

1> USE TestDB
2> go
Changed database context to 'TestDB'.

1> CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
2> go

1> INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
2> go

(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> quit

あとがき

簡単に SQL Server 2019 が試せるので、久しぶりにもう少しいじってみたい。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1