【发布时间】:2018-01-19 13:38:14
【问题描述】:
我已经准备了一个 docker-compose 文件来部署带有数据库的容器:
services:
tmp-db:
image: microsoft/mssql-server-linux:latest
environment:
ACCEPT_EULA: Y
SA_PASSWORD: yourStrong(!)Password
ports:
- 1433:1433
没关系。但现在我需要创建一个数据库并构建它的结构。我需要执行一些 sql 命令。
为了检查我是否能够做到这一点,我将command 添加到服务中:
services:
tmp-db:
image: microsoft/mssql-server-linux:latest
environment:
ACCEPT_EULA: Y
SA_PASSWORD: yourStrong(!)Password
command: /opt/mssql-tools/bin/sqlcmd -U sa -P yourStrong(!)Password -Q "SELECT [name] FROM sys.databases"
ports:
- 1433:1433
但是我得到了以下错误:
tmp-db_1 | Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
tmp-db_1 | Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x2749.
tmp-db_1 | Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
我感觉这个命令是在Sql Server 实例启动之前执行的。我该如何解决? Sql Server启动后如何执行一些sql?
【问题讨论】:
-
在此图像的 Docker Hub 页面中,MS 建议将 this project 作为在启动时设置架构和数据的示例。
标签: sql-server docker docker-compose