Install SQL Server 2019 on Docker

Shadabs-MacBook-Pro-2:~ shadab:~$ sudo docker pull mcr.microsoft.com/mssql/server:2019-CTP2.1-ubuntu
2019-CTP2.1-ubuntu: Pulling from mssql/server
Status: Downloaded newer image for mcr.microsoft.com/mssql/server:2019-CTP2.1-ubuntu

Check the new image:

Shadabs-MacBook-Pro-2:~ shadab:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mcr.microsoft.com/mssql/server 2019-CTP2.1-ubuntu 25b86ffb3a95 3 weeks ago 1.71GB

Docker container:

Shadabs-MacBook-Pro-2:~ shadab:~$ sudo docker run -e ‘ACCEPT_EULA=Y’ -e ‘SA_PASSWORD=P@ssw0rd123$#’ \
> -p 1433:1433 –name sqlserver19 \
> -d mcr.microsoft.com/mssql/server:2019-CTP2.1-ubuntu
e824e1fd453efa18ae0477487d526c0604d226245f6e6f67d1ba78cdc0cef436

Check the new container:

Shadabs-MacBook-Pro-2:~ shadab:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e824e1fd453e mcr.microsoft.com/mssql/server:2019-CTP2.1-ubuntu “/opt/mssql/bin/sqls…” 54 seconds ago Up 35 seconds 0.0.0.0:1433->1433/tcp sqlserver19

If you want to connect to the container:

Shadabs-MacBook-Pro-2:~ shadab:~$ sudo docker exec -it sqlserver19 “bash”

From here to sqlcmd:

root@25b86ffb3a95:/# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ‘P@ssw0rd123$#’
1>

If you want to access to sqlcmd from your computer:

Shadabs-MacBook-Pro-2:~ shadab:~$ sqlcmd -S localhost,1433 -U SA -P ‘P@ssw0rd123$#’
1>

Create a new database:

Shadabs-MacBook-Pro-2:~ shadab:~$ sqlcmd -S localhost,1433 -U SA -P ‘P@ssw0rd123$#’

1> CREATE DATABASE DockerDB
2> GO
1>

Check the databases created:

1> SELECT Name from sys.Databases
2> GO
Name
——————————————————————————————————————————–
master
tempdb
model
msdb
DockerDB

(5 rows affected)

Choose database for using it:

1> USE DockerDB
2> GO
Changed database context to ‘DockerDB’.

Create a table:

1> CREATE TABLE EMP (id INT, name NVARCHAR(50), DEPT NVARCHAR(15))
2> GO

Insert data:

1> INSERT INTO EMP VALUES (1, ‘Shadab’, ‘IT’); INSERT INTO EMP VALUES (2, ‘Shaukat’, ‘FINANCE’);
2> GO

(2 rows affected)

Selecting the data:

1> SELECT * FROM EMP;
2> GO
id name dept
———– ————————————————– ———–
1 Shadab IT
2 Shaukat FINANCE

(2 rows affected)

If you want to remove the installed docker:

sudo docker stop sqlserver19
sudo docker rm sqlserver19

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s