【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

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-13 15:22:02       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-13 15:22:02       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-13 15:22:02       58 阅读
  4. Python语言-面向对象

    2024-07-13 15:22:02       69 阅读

热门阅读

  1. 在鸿蒙开发中如何实现主题切换?

    2024-07-13 15:22:02       24 阅读
  2. oracle分区使用

    2024-07-13 15:22:02       23 阅读
  3. Nginx 自定义模块实现之权限控制模块

    2024-07-13 15:22:02       24 阅读
  4. 子组件向父组件传参的方式

    2024-07-13 15:22:02       18 阅读
  5. 分布式系统—Ceph对象存储系统(RGW接口)

    2024-07-13 15:22:02       21 阅读