拉取镜像
docker pull mcr.microsoft.com/mssql/server:2017-latest
启动
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=wade@123" -p 1433:1433 -v D:/database/data:/var/opt/mssql/data --name sqlserver -d mcr.microsoft.com/mssql/server:2017-latest
*密码设置不能太简单,不然启动失败
*挂载目录:D:/database/data
将数据上传至容器
docker cp 备份文件路径 sqlserver:/usr/local
进入容器
docker exec -it sqlserver bash
输入对应账号密码进入
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "wade@123"
查询文件的逻辑名
RESTORE FILELISTONLY FROM DISK = '/usr/local/备份文件.bak'
结果(LogicalName):
TeamUPDB_INSTALL_1 TeamUPDB_INSTALL_1_log
使用RESTORE DATABASE命令还原数据库
RESTORE DATABASE mytest FROM DISK = '/usr/local/OA2007DB_NEW.bak' WITH MOVE 'TeamUPDB_INSTALL_1' TO '/var/opt/mssql/data/mytest.mdf', MOVE 'TeamUPDB_INSTALL_1_log' TO '/var/opt/mssql/data/mytest.ldf', NOUNLOAD, REPLACE GO