Docker安装SQL Studio
时间: 2024-04-06 09:31:04 浏览: 150
docker-delphi:Docker Delphi RadStudio Tokio PAServer ODBC SQL服务器
你可以通过以下步骤在 Docker 容器中安装 SQL Server Management Studio:
1. 首先,使用以下命令拉取 Microsoft SQL Server Management Studio 的 Docker 镜像:
```
docker pull mcr.microsoft.com/mssql/server:2019-latest
```
2. 创建一个 Docker 容器并将端口映射到本地主机。例如:
```
docker run -d --name sqlserver -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=YourStrong!Passw0rd" -p 1433:1433 mcr.microsoft.com/mssql/server:2019-latest
```
这将创建一个名为“sqlserver”的容器,并将其绑定到本地主机的 1433 端口。
3. 进入容器并安装 SQL Server Management Studio(SSMS):
```
docker exec -it sqlserver /bin/bash
apt-get update && apt-get install -y curl apt-transport-https
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
docker exec -it sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "YourStrong!Passw0rd" -Q "CREATE DATABASE [SSMS]"
docker exec -it sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "YourStrong!Passw0rd" -Q "USE [SSMS]; CREATE LOGIN [ssms] WITH PASSWORD = 'YourStrong!Passw0rd'; CREATE USER [ssms] FOR LOGIN [ssms]; ALTER USER [ssms] WITH DEFAULT_SCHEMA=[dbo]; GRANT EXECUTE TO [ssms]; GRANT VIEW SERVER STATE TO [ssms]"
docker exec -it sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "YourStrong!Passw0rd" -Q "EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;"
docker exec -it sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "YourStrong!Passw0rd" -Q "EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE;"
docker exec -it sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "YourStrong!Passw0rd" -Q "EXECUTE xp_cmdshell 'apt-get update && apt-get install -y wget && wget https://go.microsoft.com/fwlink/?linkid=2123651 -O /tmp/ssms.deb && dpkg -i /tmp/ssms.deb'"
```
这些命令将在容器中安装 SSMS。
4. 最后,你可以通过以下命令启动 SSMS:
```
docker exec -it sqlserver /opt/mssql-tools/bin/ssms
```
这将在容器中启动 SSMS,你可以使用它来连接到 SQL Server 实例并管理数据库。
阅读全文