Docker : Basic Usage2019/02/14 |
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 |
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 |
[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: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 |
[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: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 |
Sponsored Link |
|