关于docker:在-Docker-里运行-Microsoft-SQL-服务器

3次阅读

共计 1507 个字符,预计需要花费 4 分钟才能阅读完成。

链接:https://developers.sap.com/tu…

参考代码:https://github.com/SAP-sample…

本地门路:C:\Code\referenceCode\SAP Kyma 教程例子

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.

这个例子展现了如何创立名为 DemoDB 的 MSSQL 数据库,以及名为 Orders 的数据库表,以及两行测试数据。

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

app 文件夹下的 setup.sql 负责创立数据库,数据库表和测试数据。

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

init-db.sh 文件用于配置数据库用户名和明码。

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 用于创立 docker 镜像。最初一行命令,执行 app 文件夹上面的 entrypoint.sh 文件。

Build the Docker image

依据 Dockerfile 构建一个镜像:

进入如下文件夹:

C:\Code\referenceCode\SAP Kyma 教程例子 \database-mssql

执行命令行:

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

留神,因为基于的镜像名称为 microsoft/mssql-server-linux, 故这个命令应该在 linux 操作系统里实现:

镜像胜利制作结束:

docker 镜像制作结束后,上传到 docker hub:

docker push i042416/mssql

上传胜利:

本地运行这个镜像:

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

进入镜像外部, 关上 bash shell:

docker exec -it sql1 “bash”

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

输出如下 query 命令:

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

后果:胜利读取到两条订单数据:

在 Docker 外部的 /usr/src/app 文件夹下,的确发现了我制作 docker 镜像时的文件:

Microsoft SQL 服务器,装置在 /opt 目录下:

更多 Jerry 的原创文章,尽在:” 汪子熙 ”:

正文完
 0