#安装依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2
#下载docker yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#下载docker
yum install -y docker
#配置国内镜像
[root@node1 ~]#cat /etc/docker/daemon.json
{
"registry-mirrors": [
"https://kfwkfulq.mirror.aliyuncs.com",
"https://2lqq34jg.mirror.aliyuncs.com",
"https://pee6w651.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com"
],
"dns": ["8.8.8.8","8.8.4.4"]
}
#启动&开机启动docker
systemctl start docker && systemctl enable docker
#搜索镜像
[root@node1 ~]# docker search mssql
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/microsoft/mssql-server-linux Deprecated SQL Server on Linux Container R... 1159
docker.io docker.io/microsoft/mssql-server-windows-developer Official Microsoft SQL
..........................
#下载镜像
[root@node1 ~]#docker pull microsoft/mssql-server-linux:2017-latest
#查看下载好的镜像
[root@node1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/microsoft/mssql-server-linux 2017-latest 314918ddaedf 11 months ago 1.35 GB
#创建并运行容器
[root@node1 ~]#docker run --name MSSQL_1433 -m 512m -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourpasSw0rd' --net=host -d microsoft/mssql-server-linux
[root@node1 ~]# docker start eae198ad6034(可以启动ID或者容器名)
eae198ad6034
#查看创建好的容器(UP代表已经启动)
[root@node1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eae198ad6034 314918ddaedf "/opt/mssql/bin/sq..." 24 hours ago Up 58 minutes MSSQL_1433
8b1962a03efe 314918ddaedf "/bin/bash" 25 hours ago Exited (0) 24 hours ago linuxmssql
#进入容器
[root@node1 ~]# docker exec -it eae198ad6034 /bin/bash
#进入数据库(IP是宿主机的IP,用户是大写的)
root@node1:~# /opt/mssql-tools/bin/sqlcmd -S 172.16.10.66 -U SA -P 'lihao@123'
#出现这个就表示进入数据库了
1> select name from sys.databases;
2> go
name
--------------------------------------------------------------------------------------------------------------------------
master
tempdb
model
msdb
#上传备份文件
下载winscp或者lrzsz工具,把备份文件上传宿主机,再把备份文件复制到容器的/var/opt/mssql/data/目录下
[root@node1 ~]# docker cp EastRiver.bak eae198ad6034:/var/opt/mssql/data/
root@node1:~# ll /var/opt/mssql/data/
total 1300488
drwxr-xr-x 2 root root 4096 Nov 19 14:25 ./
drwxr-xr-x 7 root root 73 Nov 18 15:23 ../
-rw-r--r-- 1 root root 205852672 Nov 4 09:43 EastRiver.bak
-rw-r----- 1 root root 4194304 Nov 19 15:14 master.mdf
-rw-r----- 1 root root 2097152 Nov 19 15:23 mastlog.ldf
-rw-r----- 1 root root 8388608 Nov 19 14:09 model.mdf
-rw-r----- 1 root root 8388608 Nov 19 14:09 modellog.ldf
-rw-r----- 1 root root 15466496 Nov 19 15:14 msdbdata.mdf
-rw-r----- 1 root root 786432 Nov 19 15:14 msdblog.ldf
-rw-r----- 1 root root 8388608 Nov 19 14:09 tempdb.mdf
-rw-r----- 1 root root 8388608 Nov 19 15:14 templog.ldf
-rw-r----- 1 root root 8388608 Nov 19 14:09 test.mdf
-rw-r----- 1 root root 8388608 Nov 19 15:09 test_log.ldf
#打开Windows下的sql管理工具(我用2008R2中文版的不行,用2012的英文版的可以,不清楚是中英文的关系,还是版本的的关系,有兴趣的你们可以试试)
新建了一个test库
create database test;
#还原数据库
后面的操作因为某些原因无法上图了,都跟Windows还原一样了,百度一下就可以了
还原成功后,就出现新的库了
#在容器上查看
1> select name from sys.databases
2> go
name
--------------------------------------------------------------------------------------------------------------------------------
master
tempdb
model
msdb
test
EastRiver
(6 rows affected)
1> use EastRiver
2> go
Changed database context to 'EastRiver'.
1> select name from sys.tables;
2> go
name
--------------------------------------------------------------------------------------------------------------------------------
BlackCardTask
ReplaceReg_D
TransRecords
Archs
RefuseReg_M
BlackCardTaskClockState
MChargeRecords
Area
......
UpLoadTable_comp2
Company
PriceHistory
CommMsg
OpLog
CardTypeConfig
OutWork_D
RealCardState
RealStateInfo
OutWork_M
EmployeeAccount
OverTime_Detail
TimeReport2
ClockDefaultParam
Scheme
ClockParams
Groups
NumberPool
DataBaseConfig
DoorTimeBound
user_log
ZKDownHis
tblAdmin
TB_FREESPACE
Accounts
(212 rows affected)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。