Docker安装sqlserver-2019
一.新建挂载目录并赋权
mkdir sqlserver
cd sqlserver
mkdir -p /data/mssql
chmod -R 777 ./data/mssql
二.准备docker-compose文件
vi docker-compose.yml
version: '3.1'
services:
sqlserver-2019:
restart: always
container_name: sqlserver-2019
image: mcr.microsoft.com/mssql/server:2019-latest
ports:
- 1433:1433
volumes:
- ./data/mssql:/var/opt/mssql
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=<pass>
三.创建数据库并测试连接
1.进入容器并连接数据库
docker exec -it sqlserver-2019 bash
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "password"
2.新建数据库
create database test_db
go
select name from sys.Databases
go
四.测试连接