0%

【Docker】Widows Container SMB

/images/20190323/0.png

之前在將公司某支程式移植到 Windows Container 時碰到一個問題,該程式會透過網路磁碟 (SMB) Eamil Template 來套版並寄出,但將網路磁碟透過 Volume 的方式 Mount 到 Container 卻抓不到檔案,查了一下才知道原來需要用 SmbGlobalMapping 掛載的網路磁碟才行

以下這段是先將要用到的網路磁碟透過 New-SmbGlobalMapping 指令掛成 T:

1
2
3
4
5
6
7
$ $User="yourUSerAccount"

$ $PWD = ConvertTo-SecureString -String "yourPassword" -AsPlainText -Force

$ $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWD

$ New-SmbGlobalMapping -LocalPath T: -RemotePath \\my-company-Filer\Files -Credential $Credential

然後在透過 Volume 即可

1
$ docker run -it -v T:\:C:\Files myContainer

不過還要特別注意的是,在 Windows Server (版本 1709),SMB 全域對應不支援 DFS、DFSN、DFSR 共用。

所以如果是 DFS 那就只好先強制指到某一台,期待哪一天 Windows Container 可以支援了