我正在尝试使用Docker在Mac上使用SQL Server。 我已经安装了映像,我正在运行SQL Server。
当我运行上面的代码并使用'docker ps'检查正在运行的容器时,容器始终停止。因此,我运行以下命令以使用容器ID启动容器。
docker start 0e84faabe9b35b2e4e8e39be3f389b38c151a3a6e7c3c82995f3ea6dc0e8ed1e 然后sql容器继续运行。
我想用VS Code连接到sql server,但是消息一直说用户'sa登录失败' 我已经安装了sql-cli来检查sql连接,但它也没有用。
我尝试使用以下凭据连接到sql server: mssql -u sa -p sa123!我给它启动sql容器。
有人可以帮我解决这个问题吗?
这就是我在VS Code中所获得的。
答案 0 :(得分:9)
调试:
让我们开始容器:
[fedora@myhost ~]$ sudo docker run -d -p 1433:1433 -e SA_PASSWORD='sa123!' -e ACCEPT_EULA=Y -i microsoft/mssql-server-linux
0031f2c49b66596cb8dc8cfec6d14351406fb924e39bd8227dfbcf7e23b67d54
容器未运行:(
[fedora@myhost ~]$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0031f2c49b66 microsoft/mssql-server-linux "/bin/sh -c /opt/m..." 21 seconds ago Exited (1) 15 seconds ago festive_meninsky
让我们看一下日志:
[fedora@myhost ~]$ sudo docker logs 0031f2c49b66596cb8dc8cfec6d14351406fb924e39bd8227dfbcf7e23b67d54
Configuring Microsoft(R) SQL Server(R)...
Microsoft(R) SQL Server(R) setup failed with error code 1. Please check the setup log in /var/opt/mssql/log for more information.
哦,好的,让我们看看。再次启动容器:
[fedora@myhost ~]$ sudo docker start 0031f2c49b66
0031f2c49b66
现在正在运行吗?
[fedora@myhost ~]$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0031f2c49b66 microsoft/mssql-server-linux "/bin/sh -c /opt/m..." 28 seconds ago Up 1 second 0.0.0.0:1433->1433/tcp festive_meninsky
让我们进去看看为什么它最后一次失败了:
[fedora@myhost ~]$ sudo docker exec -it 0031f2c49b66 /bin/bash
root@0031f2c49b66:/# cd /var/opt/mssql/log/
root@0031f2c49b66:/var/opt/mssql/log# ls
HkEngineEventFile_0_131307476136660000.xel errorlog errorlog.2 log_1.trc system_health_0_131307476143850000.xel
HkEngineEventFile_0_131307476639820000.xel errorlog.1 log.trc setup-20170205-055329.log system_health_0_131307476647330000.xel
root@0031f2c49b66:/var/opt/mssql/log# cat errorlog.1
...
2017-02-05 05:53:34.65 spid17s Server setup is starting
2017-02-05 05:53:34.65 spid17s Error: 33062, Severity: 16, State: 2.
2017-02-05 05:53:34.65 spid17s Password validation failed. The password does not meet SQL Server password policy requirements because it is too short. The password must be at least 8 characters.
2017-02-05 05:53:34.66 spid17s An error occurred while setting the server administrator (SA) password: error 33062, severity 16, state 2.
2017-02-05 05:53:34.66 spid17s An error occurred during server setup. See previous errors for more information.
...
好。让我们一瞥documentation。相关部分:
强大的系统管理员(SA)密码:至少8个字符 包括大写,小写字母,基数为10位数和/或 非字母数字符号。
嗯,让我们从头开始,牢记:
[fedora@myhost ~]$ sudo docker run -d -p 1433:1433 -e SA_PASSWORD='$uP3RC0mpl3Xp@$$w0rD' -e ACCEPT_EULA=Y microsoft/mssql-server-linux
8fcc46d9ae498948dc3cb458fb3169347fcb4f582dc6266b6569f540f2badf1d
让我们看看容器现在是否运行:
[fedora@myhost ~]$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8fcc46d9ae49 microsoft/mssql-server-linux "/bin/sh -c /opt/m..." 8 seconds ago Up 6 seconds 0.0.0.0:1433->1433/tcp competent_kalam
让我们看看是否可以建立数据库连接:
[fedora@myhost ~]$ tsql -H localhost -p 1433 -P '$uP3RC0mpl3Xp@$$w0rD' -U sa
locale is "C"
locale charset is "ANSI_X3.4-1968"
using default charset "ISO-8859-1"
1> quit