路由到默认端口上通过Docker运行的不同SQL Server实例

时间:2022-01-04 02:29:54

I can use Traefik for web sites since they use headers when they are connecting. But I want to have multiple different instances of SQL Server running through docker which will be externally available (outside the docker host, potentially outside the local network)

我可以将Traefik用于网站,因为它们在连接时使用标题。但是我希望有多个不同的SQL Server实例通过docker运行,这些实例将在外部可用(在docker主机之外,可能在本地网络之外)

So, is there anything which allows connecting to different sql server instances running on the same docker instance WITHOUT having to give them different ports or external ip addresses such that someone could access

那么,有没有什么允许连接到在同一个docker实例上运行的不同sql server实例,而不必为它们提供不同的端口或外部ip地址,以便有人可以访问

sql01.docker.local,1433 AND sql02.docker.local,1433 from SQL Tools.

来自SQL Tools的sql01.docker.local,1433和sql02.docker.local,1433。

Start Additional Question

开始附加问题

Since there has been no replies perhaps there is a way to have different instances like: sql.docker.local\instance1 and sql.docker.local\instance2 though I imagine that may also not be possible

由于没有回复,也许有一种方法可以有不同的实例,例如:sql.docker.local \ instance1和sql.docker.local \ instance2虽然我想也许不可能

End Additional Question

结束附加问题

This is an example of the docker-compose file I was trying to use (before I realised that queries to sql server don't send through a host header - or am I wrong about that?)

这是我试图使用的docker-compose文件的一个例子(之前我意识到对sql server的查询不通过主机头发送 - 或者我错了吗?)

version: '2.1'
services:
  traefik:
    container_name: traefik
    image: stefanscherer/traefik-windows
    command: --docker.endpoint=tcp://172.28.80.1:2375 --logLevel=DEBUG
    ports:
      - "8080:8080"
      - "80:80"
      - "1433:1433"
    volumes:
      - ./runtest:C:/etc/traefik
      - C:/Users/mvukomanovic.admin/.docker:C:/etc/ssl
    networks:
      - default
    restart: unless-stopped
    labels:
      - "traefik.enable=false"

  whoami:
    image: stefanscherer/whoami
    labels:
      - "traefik.backend=whoami"
      - "traefik.frontend.entryPoints=http"
      - "traefik.port=8080"
      - "traefik.frontend.rule=Host:whoami.docker.local"
    networks:
      - default
    restart: unless-stopped


  sql01:
    image: microsoft/mssql-server-windows-developer
    environment:
      - ACCEPT_EULA=Y
    hostname: sql01
    domainname: sql01.local
    networks:
      - default
    restart: unless-stopped
    labels:
      - "traefik.frontend.rule=Host:sql01.docker.local,sql01,sql01.local"
      - "traefik.frontend.entryPoints=mssql"
      - "traefik.port=1433"
      - "traefik.frontend.port=1433"
    networks:
      - default
    restart: unless-stopped    
  sql02:
    image: microsoft/mssql-server-windows-developer
    environment:
      - ACCEPT_EULA=Y
    hostname: sql02
    domainname: sql02.local
    networks:
      - default
    restart: unless-stopped
    labels:
      - "traefik.frontend.rule=Host:sql02.docker.local,sql02,sql02.local"
      - "traefik.frontend.entryPoints=mssql"
      - "traefik.port=1433"
      - "traefik.frontend.port=1433"
    networks:
      - default
    restart: unless-stopped    

networks:
  default:
    external:
      name: nat

2 个解决方案

#1


0  

you can't use traefik, because it's a HTTP reverse proxy.

你不能使用traefik,因为它是一个HTTP反向代理。

You're sql server listen and communicate via TCP.

你是sql server通过TCP监听和通信。

I don't understand what's you're final goal. Why are you using 2 differents sql-server ?

我不明白你的最终目标是什么。你为什么使用2个不同的sql-server?

It depends on what's you want but you may have two solutions:

这取决于你想要什么,但你可能有两个解决方案:

  • Can you use a simpler solution ? different databases, roles and permissions for separation.
  • 你能用更简单的解决方案吗?分离的不同数据库,角色和权限。
  • You can search into the documentation of SQL Server Always On, but it doesn't seems easy to route queries to specific sever.
  • 您可以搜索SQL Server Always On的文档,但将查询路由到特定服务器似乎并不容易。

#2


0  

There is no "virtual" access to databases like for HTTP servers. So - no additional hostnames pointing to same IP can help you.

对HTTP服务器等数据库没有“虚拟”访问权限。所以 - 没有指向同一IP的其他主机名可以帮助你。

If you insist on port 1433 for all of your instances, then I see no way for you except to use two different external IPs.

如果您坚持端口1433用于所有实例,那么除非使用两个不同的外部IP,否则我认为没办法。

If you were on a Linux box you may try some iptables magic, but it not elegant and would allow access to only one of your instances at any single moment. Windows may have iptables equivalent (I never heard of it) but still only-one-at-a-time you cannot escape.

如果你在Linux机器上,你可以尝试一些iptables魔术,但它不优雅,并且只允许在任何一个时刻访问你的一个实例。 Windows可能有相应的iptables(我从来没有听说过),但仍然只有一次,你无法逃脱。

My advice - use more than one port to expose your servers.

我的建议 - 使用多个端口来公开您的服务器。

#1


0  

you can't use traefik, because it's a HTTP reverse proxy.

你不能使用traefik,因为它是一个HTTP反向代理。

You're sql server listen and communicate via TCP.

你是sql server通过TCP监听和通信。

I don't understand what's you're final goal. Why are you using 2 differents sql-server ?

我不明白你的最终目标是什么。你为什么使用2个不同的sql-server?

It depends on what's you want but you may have two solutions:

这取决于你想要什么,但你可能有两个解决方案:

  • Can you use a simpler solution ? different databases, roles and permissions for separation.
  • 你能用更简单的解决方案吗?分离的不同数据库,角色和权限。
  • You can search into the documentation of SQL Server Always On, but it doesn't seems easy to route queries to specific sever.
  • 您可以搜索SQL Server Always On的文档,但将查询路由到特定服务器似乎并不容易。

#2


0  

There is no "virtual" access to databases like for HTTP servers. So - no additional hostnames pointing to same IP can help you.

对HTTP服务器等数据库没有“虚拟”访问权限。所以 - 没有指向同一IP的其他主机名可以帮助你。

If you insist on port 1433 for all of your instances, then I see no way for you except to use two different external IPs.

如果您坚持端口1433用于所有实例,那么除非使用两个不同的外部IP,否则我认为没办法。

If you were on a Linux box you may try some iptables magic, but it not elegant and would allow access to only one of your instances at any single moment. Windows may have iptables equivalent (I never heard of it) but still only-one-at-a-time you cannot escape.

如果你在Linux机器上,你可以尝试一些iptables魔术,但它不优雅,并且只允许在任何一个时刻访问你的一个实例。 Windows可能有相应的iptables(我从来没有听说过),但仍然只有一次,你无法逃脱。

My advice - use more than one port to expose your servers.

我的建议 - 使用多个端口来公开您的服务器。