Không thể chạy Containers, nếu phiên bản của máy chủ windows và windows containers không giống nhau, vì vậy hãy chỉ định một phiên bản cụ thể. Tham khảo các tài liệu chính thức bên dưới để biết phiên bản tương thích.
https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
# pull Windows ServerCore image
PS C:\Users\Administrator> docker pull mcr.microsoft.com/windows/servercore:1809
1809: Pulling from windows/servercore
65014b3c3121: Pull complete
9e2f2b17be72: Pull complete
Digest: sha256:17752cc071661e3cc1c1bec27d90d528fb4389d90c0412466783c2fe1c291c4e
Status: Downloaded newer image for mcr.microsoft.com/windows/servercore:1809
# display images
PS C:\Users\Administrator> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mcr.microsoft.com/windows/servercore 1809 640a8acbeb6f 33 hours ago 4.28GB
# run echo inside a container
PS C:\Users\Administrator> docker run mcr.microsoft.com/windows/servercore:1809 powershell -c "echo 'Hello Windows Container World'"
Hello Windows Container World
Kết nối với các interactive session của containers với tùy chọn [i] và [t] như sau. Nếu [exit] khỏi containers session, quá trình của containers sex kết thúc.
PS C:\Users\Administrator> docker run -it mcr.microsoft.com/windows/servercore:1809 powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\> systeminfo
Host Name: 172DABD6959C
OS Name: Microsoft Windows Server 2019 Datacenter Evaluation
OS Version: 10.0.17763 N/A Build 17763
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Server
Original Install Date: 2/7/2019, 8:25:07 PM
System Boot Time: 2/13/2019, 11:47:45 PM
System Boot Time: 2/13/2019, 11:47:45 PM
System Manufacturer: Red Hat
System Model: KVM
System Type: x64-based PC
Processor(s): 4 Processor(s) Installed.
[01]: Intel64 Family 6 Model 60 Stepping 4 GenuineIntel ~2594 Mhz
System Boo [02]: Intel64 Family 6 Model 60 Stepping 4 GenuineIntel ~2594 Mhz
System Man [03]: Intel64 Family 6 Model 60 Stepping 4 GenuineIntel ~2594 Mhz
System Mod [04]: Intel64 Family 6 Model 60 Stepping 4 GenuineIntel ~2594 Mhz
.....
.....
PS C:\> exit
PS C:\Users\Administrator> # back
Nếu thoát khỏi containers session mà vẫn giữ quy trình của containers, hãy nhấn phím Ctrl+p và Ctrl+q.
PS C:\Users\Administrator> docker run -it mcr.microsoft.com/windows/servercore:1809 powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\> # Ctrl+p, Ctrl+q
PS C:\Users\Administrator>
PS C:\Users\Administrator> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e68a751d4b2c mcr.microsoft.com/windows/servercore:1809 "powershell" 42 seconds ago Up 39 seconds silly_volhard
# connect to container's session
PS C:\Users\Administrator> docker attach e68a751d4b2c
PS C:\> hostname
e68a751d4b2c
PS C:\>
# shutdown container's process from Host's console
PS C:\Users\Administrator> docker kill e68a751d4b2c
e68a751d4b2c
PS C:\Users\Administrator> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES