英文:
Login failed for user 'sa' in ms sql linux container
问题
我正在使用Windows笔记本电脑,已安装Docker Desktop并创建了一个Docker Compose文件,成功运行并创建了映像。但是,当我尝试使用我的笔记本上的SSMS连接到SQL Server时,它不允许我这样做,并显示错误消息“登录失败,用户'sa'”。
以下是我的docker-compose.yml文件:
version: "1.0"
services:
sqlserver:
# 从Microsoft注册表中加载SQL Server映像
image: mcr.microsoft.com/mssql/server:2017-latest
environment:
- SA_PASSWORD=Password@1
- ACCEPT_EULA=Y
ports:
- "1433:1433"
volumes:
# 将SQL脚本复制到容器中
- ..\..\SQL Scripts\Initial Creation Script.sql:/var/scripts/Initial Creation Script.sql
command:
- /bin/bash
- -c
- |
# 启动MSSQL并后台运行
/opt/mssql/bin/sqlservr &
sleep 30
/opt/mssql-tools/bin/sqlcmd -U sa -P $$SA_PASSWORD -l 30 -e -i '/var/scripts/Initial Creation Script.sql' #<== 这里我只是在其中创建了一个数据库和一些表
#完成
# 为了防止容器关闭,让此线程休眠
sleep infinity
当我进入Docker Desktop中此容器的终端时,我能够使用'sa'和相同的密码使用sqlcmd
工具登录,并且我看到它已经创建了我的数据库和表格。
请注意以下事项:
在此笔记本电脑上,我已经有一个' sa '用户(在localhost上),密码不同,是否会干扰此操作?如果是的话,我如何为我的Docker映像创建一个仅具有sys
访问权限的特殊用户,用于我的数据库fithub
,可能类似于FithubDBUser
,并使用一些自定义密码,我可以在Docker Compose文件中执行吗?
谢谢。
英文:
I am using windows laptop and installed docker desktop and created a docker compose file and I am able to run it succesfully and it creates the images but when i try to connect to that sql server using my laptops ssms it is not allowing me to do so and giving error 'login failed for user 'sa'
Here is my docker-compose.yml
version: "1.0"
services:
sqlserver:
# load the sql server image from microsoft registry
image: mcr.microsoft.com/mssql/server:2017-latest
environment:
- SA_PASSWORD=Password@1
- ACCEPT_EULA=Y
ports:
- "1433:1433"
volumes:
# copy the sql scripts to container
- ..\..\SQL Scripts\Initial Creation Script.sql:/var/scripts/Initial Creation Script.sql
command:
- /bin/bash
- -c
- |
# Launch MSSQL and send to background
/opt/mssql/bin/sqlservr &
sleep 30
/opt/mssql-tools/bin/sqlcmd -U sa -P $$SA_PASSWORD -l 30 -e -i '/var/scripts/Initial Creation Script.sql' #<== here I am just creating a db and some tables in it
#done
# So that the container doesn't shut down, sleep this thread
sleep infinity
when i go to terminal of this container in docker desktop I am able to login using 'sa' with the same password using sqlcmd
utility and I see that it has created my DB and tables as well
I am not sure what is wrong with this. this was working in my old laptop and now I got a new laptop and everything is broken, obviusly this is not the reason
some facts:
In this laptop I already have a 'sa' user (on localhost) with different password, is that hampering this?!! , if yes how can i create a special user for my docker image only with sys
access for my database fithub
, may be something like FithubDBUser
with some custom password, can i do it in docker compose file?
thank you
答案1
得分: 0
我能从评论中得到答案,感谢所有评论者,我已经在我的本地笔记本上的本地主机上的端口1433上监听了localhost,并且该实例也具有sa
用户(密码不同),所以当我更改了我的docker-compose.yml
文件以将其映射到不同的端口时,它起作用了。
这是编辑后的docker-compose.yml
:
version: "1.0"
services:
sqlserver:
# 从Microsoft注册表中加载SQL Server映像
image: mcr.microsoft.com/mssql/server:2017-latest
environment:
- SA_PASSWORD=Password@1
- ACCEPT_EULA=Y
ports:
- "1434:1433"
我会将这个问题标记为已回答。不知何故,另一个问题在我脑海中浮现,
我们如何判断主机机器上将使用哪些端口,可能会发生1434也被使用的情况?但我将进行一些研究,如果需要的话会在这里发布。
英文:
I was able to get the answer from the comments, thanks to all the commentors, I already had localhost listening on my local laptop on 1433, and that instance also had sa
user (with different password), so it was not getting connected, when I changed my docker-compose.yml
file to map it to a different port it worked.
Here is the edited docker-compose.yml
version: "1.0"
services:
sqlserver:
# load the sql server image from microsoft registry
image: mcr.microsoft.com/mssql/server:2017-latest
environment:
- SA_PASSWORD=Password@1
- ACCEPT_EULA=Y
ports:
- "1434:1433"
I will mark this question as answered. Somehow another question is popping up in my head,
> how can we gauge what ports will be in use on host machine, it might
> happen 1434 is also getting used? but I will do some research and if
> needed will post here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论