Running Microsoft SQL Server in docker

Time:2021-7-27

Link:https://developers.sap.com/tu…

Reference code:https://github.com/SAP-sample…

Local path: C: \ code \ referencecode \ SAP kyma tutorial example

This sample provides the MS SQL database configured with a sample DemoDB database which contains one Orders table populated with two rows of sample data.

This example shows how to create an MSSQL database named demodb, a database table named orders, and two rows of test data.

The app/setup.sql file handles the generation of the database, table, and data.

Setup.sql in the app folder is responsible for creating databases, database tables and test data.

Running Microsoft SQL Server in docker

Within the app/init-db.sh file, you can also configure the database user and password.

The init-db.sh file is used to configure the database user name and password.

Running Microsoft SQL Server in docker

Docker folder

Running Microsoft SQL Server in docker

  • FROM:The FROM instruction initializes a new build stage and sets the Base Image for subsequent instructions. As such, a valid Dockerfile must start with a FROM instruction. The image can be any valid image – it is especially easy to start by pulling an image from the Public Repositories.

Dockerfile is used to create a docker image. The last line of command executes the entrypoint.sh file under the app folder.

Build the Docker image

Build an image according to dockerfile:

Enter the following folder:

C: \ code \ referencecode \ SAP kyma tutorial example \ database MSSQL

Execute command line:

docker build -t i042416/mssql -f docker/Dockerfile .

Running Microsoft SQL Server in docker

Note that because the image name based on is Microsoft / MSSQL server linux, this command should be completed in the Linux operating system:

Running Microsoft SQL Server in docker

Image creation completed successfully:
Running Microsoft SQL Server in docker

After the docker image is created, upload it to the docker hub:

docker push i042416/mssql

Upload succeeded:

Running Microsoft SQL Server in docker

Run this image locally:

sudo docker run -e ACCEPT_EULA=Y -e SA_PASSWORD=Yukon900 -p 1433:1433 –name sql1 -d i042416/mssql

Go inside the image and open bash shell:

docker exec -it sql1 “bash”

Running Microsoft SQL Server in docker

Start the sqlcmd tool, which allows you to run queries against the database, by running this command: /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P Yukon900

Enter the following query command:

1> USE DemoDB
2> SELECT * FROM ORDERS
3> GO

Running Microsoft SQL Server in docker

Result: two order data were successfully read:
Running Microsoft SQL Server in docker

In the / usr / SRC / APP folder inside docker, I did find the file when I made the docker image:

Running Microsoft SQL Server in docker

Microsoft SQL server, installed in / opt Directory:
Running Microsoft SQL Server in docker

Running Microsoft SQL Server in docker

More Jerry’s original articles are: “Wang Zixi”:
Running Microsoft SQL Server in docker