您好,登錄后才能下訂單哦!
#安裝依賴包
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。