Windows容器使用阿里云NAS SMB文件系统做持久化存储目录
生活随笔
收集整理的這篇文章主要介紹了
Windows容器使用阿里云NAS SMB文件系统做持久化存储目录
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
轉(zhuǎn)載于:https://developer.aliyun.com/article/772570
一、簡介
隨著Windows容器逐漸普及和發(fā)展,Windows容器持久化存儲以及容器間共享的需求越來越高漲。 本文介紹如何讓W(xué)indows主機(jī)正確配置NAS SMB文件系統(tǒng),支持Windows容器讓Docker鏡像使用掛載NAS SMB文件系統(tǒng)的子目錄作為持久化存儲目錄。
二、掛載步驟
打開Powershell,使用New-SmbGlobalMapping命令進(jìn)行掛載
# Define clear text string for username and password [string]$userName = 'workshop\administrator' [string]$userPassword = '???' # Convert to SecureString [securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force [pscredential]$credObject = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword) # Mount SMB share for container New-SmbGlobalMapping -LocalPath z: -RemotePath \\file-system-id.region.nas.aliyuncs.com\myshare -Persistent $true -Credential $credObject
注意New-SmbGlobalMapping掛載命令使用的用戶名是workshop/administrator,密碼需要填上ECS的administrator密碼。
使用New-Item創(chuàng)建鏈接,作為容器的數(shù)據(jù)共享盤
New-Item -ItemType SymbolicLink -Value \\file-system-id.region.nas.aliyuncs.com\myshare -Path c:\datashare
在cmd命令行使用docker run命令運(yùn)行容器。注意選擇ECS操作系統(tǒng)版本對應(yīng)的容器鏡像
docker run -ti --rm -v c:\datashare:c:\data --entrypoint="" registry.cn-hangzhou.aliyuncs.com/acs/flexvolume:v1.16.9.205f5a3-windows1809 pwsh.exe
完成之后在彈出的容器命令行界面中,即可對c:\data目錄進(jìn)行操作,內(nèi)容會存儲在NAS SMB卷中
三、開機(jī)自啟動步驟
以上步驟經(jīng)過改進(jìn),可以做成開啟啟動腳本,使得機(jī)器啟動后即可生成帶持久化存儲目錄的容器
1. 在C盤創(chuàng)建c:\startup_script.ps1腳本
# Define clear text string for username and password [string]$userName = 'workshop\administrator' [string]$userPassword = '???' # Convert to SecureString [securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force [pscredential]$credObject = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword) New-SmbGlobalMapping -LocalPath y: -RemotePath \\file-system-id.region.nas.aliyuncs.com\myshare -Persistent $true -Credential $credObject New-Item -ItemType SymbolicLink -Value \\file-system-id.region.nas.aliyuncs.com\myshare -Path c:\datashare
2. 在C盤創(chuàng)建startup_script.bat腳本
ECHO ON ECHO This startup_script will mount smb share and start container powershell -file "c:\startup_script.ps1" >> c:\startup_script.output.txt docker run -ti --rm -v c:\datashare:c:\data --entrypoint="" registry.cn-hangzhou.aliyuncs.com/acs/flexvolume:v1.16.9.205f5a3-windows1809 pwsh.exe
3. 在cmd命令行運(yùn)行以下命令,生成開機(jī)任務(wù)
schtasks /create /tn "startup_script" /tr "c:\startup_script.bat" /sc onstart /RU SYSTEM /RL HIGHEST schtasks /run /tn "startup_script"
4. 上述步驟即配置完成開機(jī)任務(wù)。以后每次開機(jī)啟動之后,即可運(yùn)行以下docker命令打開容器命令行,操作c:\data持久化存儲目錄
4.1. 使用docker ps找到container ID
4.2. 使用docker exec打開容器命令行,可以看到c:\data持久化存儲目錄
總結(jié)
以上是生活随笔為你收集整理的Windows容器使用阿里云NAS SMB文件系统做持久化存储目录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: setex()
- 下一篇: 《EC20 — 利用PPP实现4G模块联