Docker : Basic Usage2019/03/04 |
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. |
Windows PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved. # pull Windows ServerCore image PS C:\Users\Administrator> docker pull microsoft/windowsservercore Using default tag: latest latest: Pulling from microsoft/windowsservercore 3889bb8d808b: Pull complete d0c71fc8924e: Pull complete Digest: sha256:05de0a0ac13d3652bd1f2281b8589459ebb611092e3fe4d8f1be91f1f6984266 Status: Downloaded newer image for microsoft/windowsservercore:latest # list images PS C:\Users\Administrator> docker images REPOSITORY TAG IMAGE ID CREATED SIZE microsoft/windowsservercore latest ea9f7aa13d03 7 weeks ago 11GB # run echo inside a Container PS C:\Users\Administrator> docker run microsoft/windowsservercore 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 -i -t microsoft/windowsservercore powershell Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. PS C:\> systeminfo Host Name: 0CAEA0EB3105 OS Name: Microsoft Windows Server 2016 Datacenter Evaluation OS Version: 10.0.14393 N/A Build 14393 OS Manufacturer: Microsoft Corporation OS Configuration: Standalone Server OS Build Type: Multiprocessor Free Registered Owner: N/A Registered Organization: N/A Product ID: 00377-90000-00001-AA325 Original Install Date: 1/2/2019, 4:01:44 PM System Boot Time: 3/4/2019, 12:00:46 AM System Manufacturer: Red Hat System Model: KVM System Type: x64-based PC Processor(s): 4 Processor(s) Installed. [01]: Intel64 Family 6 Model 63 Stepping 2 GenuineIntel ~2594 Mhz [02]: Intel64 Family 6 Model 63 Stepping 2 GenuineIntel ~2594 Mhz [03]: Intel64 Family 6 Model 63 Stepping 2 GenuineIntel ~2594 Mhz [04]: Intel64 Family 6 Model 63 Stepping 2 GenuineIntel ~2594 Mhz BIOS Version: SeaBIOS 1.11.0-2.el7, 4/1/2014 Windows Directory: C:\Windows System Directory: C:\Windows\system32 Boot Device: \Device\HarddiskVolume1 ..... ..... 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 microsoft/windowsservercore powershell Windows PowerShell Copyright (C) 2016 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 5337b53aeb49 microsoft/windowsservercore "powershell" 28 seconds ago Up 25 seconds sharp_wu # connect to container's session PS C:\Users\Administrator> docker attach 5337b53aeb49 PS C:\> hostname 5337b53aeb49 PS C:\> # shutdown container's process from Host's console PS C:\Users\Administrator> docker kill 5337b53aeb49 e68a751d4b2c PS C:\Users\Administrator> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
Sponsored Link |