如何使用Dockerized SQL Server for Linux建立MSDTC



我正在尝试使用Docker Compose在SQL Server容器中设置MSDTC,如下所述:

https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-configure-msdtc-docker?view=sql-server-ver15

我的撰写文件看起来像这样,反映了上面文档中引用的命令行参数:

services:
pte_mssql:
build:
context: ./mssql/docker
environment:
ACCEPT_EULA: 'Y'
MSSQL_SA_PASSWORD: '${startupSaPassword}'
MSSQL_RPC_PORT: 135
MSSQL_DTC_TCP_PORT: 51000
ports:
- 1433:1433
- 135:135
- 51000:51000

但是,DTC服务似乎没有启动。我在输出中看到这种重复(其他端口似乎没有问题):

Waiting for TCP socket on 172.24.0.1:51000 of 'pte_mssql_1' (Connection refused (Connection refused))
Will use 172.24.0.1 (network vestmarkone_default) as host of pte_mssql
More forwarded TCP ports for service 'pte_mssql:135 [[HostIp:0.0.0.0, HostPort:135], [HostIp:::, HostPort:135]]'. Will use the first one.
More forwarded TCP ports for service 'pte_mssql:1433 [[HostIp:0.0.0.0, HostPort:1433], [HostIp:::, HostPort:1433]]'. Will use the first one.
More forwarded TCP ports for service 'pte_mssql:51000 [[HostIp:0.0.0.0, HostPort:51000], [HostIp:::, HostPort:51000]]'. Will use the first one.

我使用以下命令来确认端口51000上没有任何运行:

root@906e7184f6bc:/var/opt/mssql/log# lsof -i -P -n | grep LISTEN
sqlservr   9 root   49u  IPv4 1613252      0t0  TCP *:135 (LISTEN)
sqlservr   9 root   51u  IPv6 1613254      0t0  TCP *:135 (LISTEN)
sqlservr   9 root   64u  IPv6 1617097      0t0  TCP *:1433 (LISTEN)
sqlservr   9 root  100u  IPv4 1617098      0t0  TCP *:1433 (LISTEN)
sqlservr   9 root  106u  IPv4 1629465      0t0  TCP 127.0.0.1:1434 (LISTEN)
sqlservr   9 root  110u  IPv4 1617101      0t0  TCP 127.0.0.1:1431 (LISTEN)

我还尝试将以下内容添加到我的Dockerfile而不是设置MSSQL_DTC_TCP_PORT环境变量:

RUN /opt/mssql/bin/mssql-conf set distributedtransaction.servertcpport 51000

这不能解决问题。

无论如何,从命令行创建容器(如本文所示)而不是通过Docker Compose产生相同的结果。请注意,我以root身份启动容器,因此我可以运行lsof来进行故障排除。我还用了"2019-最新";而不是"2019- ga -ubuntu-20.04";由于后者似乎已不存在:

docker run 
-u root 
-e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=pass@1234' 
-e 'MSSQL_RPC_PORT=135' -e 'MSSQL_DTC_TCP_PORT=51000' 
-p 1433:1433 -p 135:135 -p 51000:51000  
-d mcr.microsoft.com/mssql/server:2019-latest

有没有人对如何启用DTC服务或如何进一步排除故障有任何建议?

根据微软的文档,在分布式事务开始之前,DTC服务器不会开始侦听。一旦出现这种情况,您应该会看到它在端口51000上侦听。

最新更新