#安裝依賴包 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;
#還原數據庫
node
後面的操做由於某些緣由沒法上圖了,都跟Windows還原同樣了,百度一下就能夠了
還原成功後,就出現新的庫了
linux
#在容器上查看 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)sql