How to install Sql Server 2019 on docker

You can follow the instructions from the microsoft web: https://docs.microsoft.com/es-es/sql/linux/quickstart-install-connect-docker?view=sql-server-linux-ver15

Install the image from the microsoft store:

sergio@sergio-pc:~$ sudo docker pull mcr.microsoft.com/mssql/server:2019-CTP2.1-ubuntu
[sudo] contraseña para sergio: 
2019-CTP2.1-ubuntu: Pulling from mssql/server
59ab41dd721a: Pull complete 
57da90bec92c: Pull complete 
06fe57530625: Pull complete 
5a6315cba1ff: Pull complete 
739f58768b3f: Pull complete 
0b751601bca3: Pull complete 
bcf04a22644a: Pull complete 
440dfb194122: Pull complete 
1be753d5072a: Pull complete 
Digest: sha256:c85030008fb886a30beffc931c2ecbe9d95d5119a66868d35bf878da8e9521e5
Status: Downloaded newer image for mcr.microsoft.com/mssql/server:2019-CTP2.1-ubuntu

 

Check the new image:

sergio@sergio-pc:~$ sudo docker images
REPOSITORY                                          TAG                  IMAGE ID            CREATED             SIZE
mcr.microsoft.com/mssql/server                      2019-CTP2.1-ubuntu   25b86bfb3a93        2 weeks ago         1.71GB

 

Docker container:

sergio@sergio-pc:~$ sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong!Passw0rd' \
>    -p 1433:1433 --name sqlserver19 \
>    -d mcr.microsoft.com/mssql/server:2019-CTP2.1-ubuntu
e824e1fd453efa18ae0477487d526c0604d226245f6e6f67d1ba78cdc0cef436

 

Check the new container:

sergio@sergio-pc:~$ 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…"   28 seconds ago      Up 26 seconds               0.0.0.0:1433->1433/tcp   sqlserver19

 

If you want to connect to the container:

sergio@sergio-pc:~$ sudo docker exec -it sqlserver19 "bash"
root@e824e1fd453e:/#

 

From here to sqlcmd:

root@e824e1fd453e:/# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd'
1>

 

If you want to access to sqlcmd from your computer:

sergio@sergio-pc:~$ sqlcmd -S localhost,1433 -U SA -P 'YourStrong!Passw0rd'
1>

 

Create a new database:

sergio@sergio-pc:~$ sqlcmd -S localhost,1433 -U SA -P 'YourStrong!Passw0rd'
1> CREATE DATABASE TestDB
2> GO
1>

 

Check the databases created:

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

(5 rows affected)

 

Choose database for using it:

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

 

Create a table:

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

 

Insert some data:

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

(1 rows affected)

(1 rows affected)

 

Select the data:

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

(1 rows affected)

 

If you want to remove the installed docker:

sudo docker stop sqlserver19
sudo docker rm sqlserver19

 

Adding value with arumel!!