【Docker Install SQL Server】

Docker Install SQL Server

Docker pull

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

bash 复制代码
docker pull mcr.microsoft.com/mssql/server

Docker run

bash 复制代码
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

bash 复制代码
docker exec -it mssql2022 "bash"

use sqlcmd connect sql server

bash 复制代码
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

sql 复制代码
CREATE DATABASE TestDB;

SELECT Name from sys.databases;

GO

create new table

sql 复制代码
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

sql 复制代码
SELECT * FROM Inventory WHERE quantity > 152;

GO
相关推荐
一休哥助手23 分钟前
深入理解 Docker 网桥配置与网络管理
docker·容器·eureka
cnsinda_sdc33 分钟前
信创数据防泄漏中信创沙箱是什么样的安全方案
运维·网络·安全·源代码管理·源代码防泄密·源代码加密
KevinRay_36 分钟前
命令行之巅:Linux Shell编程的至高艺术(中)
linux·运维·服务器·重定向·shell编程
PittDing2 小时前
【更新】Docker新手入门教程2:在Windows系统通过compose创建多个mysql镜像并配置应用
windows·mysql·docker
后端转全栈_小伵2 小时前
MySQL外键类型与应用场景总结:优缺点一目了然
数据库·后端·sql·mysql·学习方法
努力的小T3 小时前
Linux apt-mirror 同步搭建本地源详解教程
linux·运维·服务器·ubuntu·云计算·debian
Mitch3113 小时前
【漏洞复现】CVE-2014-3120 & CVE-2015-1427 Expression Injection
运维·web安全·elasticsearch·docker·apache
路飞雪吖~3 小时前
【Linux】编写简易shell && 深度理解命令行解释器 && 环境变量 && 内建命令
linux·运维·服务器
神奇侠20243 小时前
基于Centos7.X系统端口占用处理
linux·运维·服务器
m0_748251084 小时前
docker安装nginx,docker部署vue前端,以及docker部署java的jar部署
java·前端·docker