Docker : Basic Usage2022/01/21 |
This is the Basic Usage of Docker.
Run PowerShell or Command Prompt to use it. |
|
[1] |
Download Windows official image and run [echo] inside a Container.
It's impossible to run Containers if the Version of Host Windows and Container Windows are not the same one,
so specify a specific version when pulling an image. Refer to the official documents below for version compatibility. ⇒ https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility?tabs=windows-server-2022%2Cwindows-10-21H1
You can find the catalog of container images on the following site.
⇒ https://mcr.microsoft.com/v2/_catalog
You can find the tag list of a specific container images on the following site.
⇒ https://mcr.microsoft.com/v2/(namespace)/(repo)/tags/list ex : https://mcr.microsoft.com/v2/windows/servercore/tags/list |
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. # pull Windows ServerCore image PS C:\Users\Administrator> docker pull mcr.microsoft.com/windows/servercore:ltsc2022 ltsc2022: Pulling from windows/servercore 8f616e6e9eec: Pull complete 0e02c12b1310: Pull complete Digest: sha256:08d5f2a16e6a588ee9ed2a6d1a89cca1749f93773997507a73449f7eb16afba4 Status: Downloaded newer image for mcr.microsoft.com/windows/servercore:ltsc2022 mcr.microsoft.com/windows/servercore:ltsc2022 # display images PS C:\Users\Administrator> docker images REPOSITORY TAG IMAGE ID CREATED SIZE mcr.microsoft.com/windows/servercore ltsc2022 11cbc9e36c7a 4 days ago 4.95GB # run echo inside a container PS C:\Users\Administrator> docker run mcr.microsoft.com/windows/servercore:ltsc2022 powershell -c "echo 'Hello Windows Container World'" Hello Windows Container World |
[2] | Connect to the interactive session of a Container with [i] and [t] option like follows. If [exit] from the Container session, the process of a Container finishes. |
PS C:\Users\Administrator> docker run -it mcr.microsoft.com/windows/servercore:ltsc2022 powershell Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. PS C:\> systeminfo Host Name: 46CF97D73BA4 OS Name: Microsoft Windows Server 2022 Datacenter OS Version: 10.0.20348 N/A Build 20348 OS Manufacturer: Microsoft Corporation OS Configuration: Standalone Server OS Build Type: Multiprocessor Free Registered Owner: N/A Registered Organization: N/A Product ID: 00454-60000-00001-AA069 Original Install Date: 1/16/2022, 5:18:39 AM System Boot Time: 1/20/2022, 5:14:20 PM System Manufacturer: VMware, Inc. System Model: VMware7,1 System Type: x64-based PC Processor(s): 8 Processor(s) Installed. [01]: AMD64 Family 23 Model 8 Stepping 2 AuthenticAMD ~3493 Mhz [02]: AMD64 Family 23 Model 8 Stepping 2 AuthenticAMD ~3493 Mhz ..... ..... PS C:\> exit PS C:\Users\Administrator> # come back |
[3] | If exit from the Container session with keeping container's process, push Ctrl+p, and Ctrl+q key. |
PS C:\Users\Administrator> docker run -it mcr.microsoft.com/windows/servercore:ltsc2022 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 243f6b31662a mcr.microsoft.com/windows/servercore:ltsc2022 "powershell" 15 seconds ago Up 13 seconds youthful_joliot # connect to container's session PS C:\Users\Administrator> docker attach 243f6b31662a PS C:\> hostname 243f6b31662a PS C:\> # shutdown container's process from Host's console PS C:\Users\Administrator> docker kill 243f6b31662a 243f6b31662a PS C:\Users\Administrator> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
Sponsored Link |
|