1.拉取MSSQL最新版本
docker pull mcr.microsoft.com/mssql/server:2019-latest
2.拉取完之后就可以运行了
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=你的数据库密码" --name mssql2019 -p 1433:1433 -v /zdata/mssql:/var/opt/mssql -d mcr.microsoft.com/mssql/server
一定要注意
-v /zdata/mssql:/var/opt/mssql
这个东西是将物理机的 /zdata/mssql 目录映射到容器中
运行正常之后就可以在自己电脑连接数据库了
3.修改密码
docker exec -it mssql2019 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "旧密码" -Q 'ALTER LOGIN SA WITH PASSWORD="新密码"'
4.值得注意的是,服务器的内存必须在2G以上,不然安装失败
如果因为内存不足安装失败,可通过
docker logs [容器名]
查看docker容器日志,会有提示如下
SQL Server 2019 will run as non-root by default. This container is running as user mssql. To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216. sqlservr: This program requires a machine with at least 2000 megabytes of memory. /opt/mssql/bin/sqlservr: This program requires a machine with at least 2000 megabytes of memory.