使用 gMSA 運行容器
適用於:Windows Server 2025、Windows Server 2022、Windows Server 2019
若要使用群組受控服務帳戶執行容器 (gMSA),請提供認證規格檔案給 docker run的 --security-opt
參數:
docker run --security-opt "credentialspec=file://contoso_webapp01.json" --hostname webapp01 -it mcr.microsoft.com/windows/server:ltsc2022 powershell
重要
在 Windows Server 2016 版本 1709 和 1803 上,容器的主機名必須符合 gMSA 簡短名稱。
在上述範例中,gMSA SAM 帳戶名稱 webapp01,因此容器主機名也會命名為 webapp01。
在 Windows Server 2019 和更新版本中,不需要主機名字段,但即使明確提供不同的主機名,容器仍會以 gMSA 名稱來識別自己,而不是主機名。
若要檢查 gMSA 是否正常運作,請在容器中執行下列 Cmdlet:
# Replace contoso.com with your own domain
PS C:\> nltest /sc_verify:contoso.com
Flags: b0 HAS_IP HAS_TIMESERV
Trusted DC Name \\dc01.contoso.com
Trusted DC Connection Status Status = 0 0x0 NERR_Success
Trust Verification Status = 0 0x0 NERR_Success
The command completed successfully
如果受信任的 DC 連線狀態和信任驗證狀態未 NERR_Success
,請遵循 疑難解答指示 來偵錯問題。
您可以執行下列命令並檢查用戶端名稱,以驗證容器內的 gMSA 身分識別:
PS C:\> klist get webapp01
Current LogonId is 0:0xaa79ef8
A ticket to krbtgt has been retrieved successfully.
Cached Tickets: (2)
#0> Client: webapp01$ @ CONTOSO.COM
Server: krbtgt/webapp01 @ CONTOSO.COM
KerbTicket Encryption Type: AES-256-CTS-HMAC-SHA1-96
Ticket Flags 0x40a10000 -> forwardable renewable pre_authent name_canonicalize
Start Time: 3/21/2019 4:17:53 (local)
End Time: 3/21/2019 14:17:53 (local)
Renew Time: 3/28/2019 4:17:42 (local)
Session Key Type: AES-256-CTS-HMAC-SHA1-96
Cache Flags: 0
Kdc Called: dc01.contoso.com
[...]
若要開啟 PowerShell 或其他控制台應用程式作為 gMSA 帳戶,您可以要求容器在網路服務帳戶下執行,而不是一般的 ContainerAdministrator (或 NanoServer 的 ContainerUser) 帳戶:
# NOTE: you can only run as Network Service or SYSTEM on Windows Server 1709 and later
docker run --security-opt "credentialspec=file://contoso_webapp01.json" --hostname webapp01 --user "NT AUTHORITY\NETWORK SERVICE" -it mcr.microsoft.com/windows/servercore:ltsc2019 powershell
當您以網路服務身分執行時,您可以嘗試連線到域控制器上的 SYSVOL,以 gMSA 測試網路驗證:
# This command should succeed if you're successfully running as the gMSA
PS C:\> dir \\contoso.com\SYSVOL
Directory: \\contoso.com\sysvol
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----l 2/27/2019 8:09 PM contoso.com
相關內容
除了執行容器之外,您也可以使用 gMSA 來:
如果您在設定過程中遇到任何問題,請查看我們的 疑難解答指南 以尋找可能的解決方案。