在 Docker 里运行 Microsoft SQL 服务器
鏈接: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 目錄下:
更多Jerry的原創文章,盡在:“汪子熙”:
總結
以上是生活随笔為你收集整理的在 Docker 里运行 Microsoft SQL 服务器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SAP CRM Fiori Simula
- 下一篇: linux cmake编译源码,linu