【Docker Install SQL Server】

Docker Install SQL Server

Docker pull

first step pull image: https://hub.docker.com/r/microsoft/mssql-server

docker pull mcr.microsoft.com/mssql/server

Docker run

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=yourStrong(!)Password" -e "MSSQL_PID=Evaluation" -p 1433:1433  --name mssql2022 -d mcr.microsoft.com/mssql/server

Environment Variables
You can use environment variables to configure SQL Server on Linux Containers.

ACCEPT_EULA confirms your acceptance of the End-User Licensing Agreement.

MSSQL_SA_PASSWORD is the database system administrator (userid = ‘sa’) password used to connect to SQL Server once the container is running. Important note: This password needs to include at least 8 characters of at least three of these four categories: uppercase letters, lowercase letters, numbers and non-alphanumeric symbols.

MSSQL_PID is the Product ID (PID) or Edition that the container will run with. Acceptable values:

  • Developer : This will run the container using the Developer Edition (this is the default if no -MSSQL_PID environment variable is supplied)
  • Express : This will run the container using the Express Edition
  • Standard : This will run the container using the Standard Edition
  • Enterprise : This will run the container using the Enterprise Edition
  • EnterpriseCore : This will run the container using the Enterprise Edition Core : This will run the container with the edition that is associated with the PID

Docker exec

docker exec -it mssql2022 "bash"

use sqlcmd connect sql server

mssql@ecf27c316472:/$ /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P yourPassword
1> select @@version
2> go
                                                                                                                                                                                                                                             
Microsoft SQL Server 2022 (RTM-CU13) (KB5036432) - 16.0.4125.3 (X64)
        May  1 2024 15:05:56
        Copyright (C) 2022 Microsoft Corporation
        Developer Edition (64-bit) on Linux (Ubuntu 22.04.4 LTS) <X64>

create new database

CREATE DATABASE TestDB;

SELECT Name from sys.databases;

GO

create new table

USE TestDB;

CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT);

INSERT INTO Inventory VALUES (1, 'banana', 150); 
INSERT INTO Inventory VALUES (2, 'orange', 154);

GO

query data

SELECT * FROM Inventory WHERE quantity > 152;

GO
  • 11
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 SQL Server Dockerfile,可以用于部署 SQL Server: ``` # 基于官方的 Ubuntu 20.04 镜像 FROM ubuntu:20.04 # 更新 apt-get 软件源 RUN apt-get update && \ apt-get -y install curl gnupg2 && \ curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \ curl https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list > /etc/apt/sources.list.d/mssql-server.list && \ apt-get update && \ apt-get -y install mssql-server # 设置 SQL Server SA 用户的密码 ENV MSSQL_SA_PASSWORD=StrongPassword123 # 启动 SQL Server 并创建一个新的数据库 CMD /opt/mssql/bin/sqlservr & (sleep 10 && /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $MSSQL_SA_PASSWORD -Q "CREATE DATABASE MyDatabase") && tail -f /var/opt/mssql/log/errorlog ``` 这个 Dockerfile 将基于 Ubuntu 20.04 镜像,并安装 curl 和 gnupg2 以帮助更新 apt-get 软件源。接着,它将通过下载和添加 Microsoft 的 GPG 密钥和添加 SQL Server 2019 的软件源来安装 SQL Server。然后它设置 SQL Server SA 用户的密码并启动 SQL Server。最后,它将创建一个名为 MyDatabase 的新数据库。 要构建此 Dockerfile,请使用以下命令: ``` docker build -t sql-server . ``` 然后,您可以使用以下命令运行 SQL Server 容器: ``` docker run -d -p 1433:1433 --name sql-server -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=StrongPassword123 sql-server ``` 这将在 Docker 容器中运行 SQL Server,并将容器的端口 1433 映射到主机的端口 1433。注意,这里使用了 ACCEPT_EULA 和 MSSQL_SA_PASSWORD 环境变量来接受许可协议并设置 SQL Server SA 用户的密码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值