在 Docker 里运行 Microsoft SQL 服务器

举报
Jerry Wang 发表于 2022/06/11 17:49:51 2022/06/11
【摘要】 链接:https://developers.sap.com/tutorials/cp-kyma-mssql-deployment.html参考代码:https://github.com/SAP-samples/kyma-runtime-extension-samples本地路径:C:\Code\referenceCode\SAP Kyma教程例子This sample provides th...

链接:https://developers.sap.com/tutorials/cp-kyma-mssql-deployment.html

参考代码:https://github.com/SAP-samples/kyma-runtime-extension-samples

本地路径: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 目录下:

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。