Docker下安装Sqlserver(mssql)

1.服务器需要大于2G内存。如果不够则可能无法正常启动,查看日志报如下错误:
This program requires a machine with at least 2000 megabytes of memory

2.获取sqlserver镜像

docker pull mcr.microsoft.com/mssql/server:2017-latest

镜像下载成功后,运行镜像

docker run -e ACCEPT_EULA=Y -e MSSQL_PID="Developer" -e MSSQL_SA_PASSWORD="sa" -e MSSQL_TCP_PORT=1234 -p 1234:1234 --name sqlserver -d mcr.microsoft.com/mssql/server:2017-latest

运行容器报错:
SQL Server 2019 will run as non-root by default.
This container is running as user root.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
The SQL Server End-User License Agreement (EULA) must be accepted before SQL
Server can start. The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746388.

You can accept the EULA by specifying the --accept-eula command line option,
setting the ACCEPT_EULA environment variable, or using the mssql-conf tool.

 3.登录sqlserver容器

docker exec -it sqlserver "bash"

4.连接sqlserver

/opt/mssql-tools/bin/sqlcmd -S localhost,1234 -U SA -P 'Lc19951127.'

 

5.执行sql

英文的操作系统  对于有中文的  我定义类型  nvarchar(100)  

插入时:
insert into users values(N'张三');
go

 

 这个是docker for windows 安装的,接下来我会去mac里具体使用

参考:https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-configure-docker?view=sql-server-2017

原文地址:https://www.cnblogs.com/LiChen19951127/p/12802965.html