Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 6개 있습니다.)

Windows 10에서 경험해 보는 Windows Containers와 docker

2016-08-02부터 시작된 윈도우 10 1주년 업데이트는 빌드 번호가 14393이고 이는 "Windows Containers" 요구 사항에 부합합니다.

Windows container requirements
; https://learn.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/system-requirements

OS Requirements: ... Windows 10 Professional and Enterprise (insiders build 14352 and up).

아쉽게도 "Supported OS images"에 보면, "Nano Server image"만 Windows 10에서 가능하다고 합니다. 제한된 환경이긴 하지만 docker를 이해하는 정도로 실습해 보는 용도라면 손색이 없습니다.

우선, Windows Containers는 격리 수준에 따라 다음과 같이 2가지로 나뉩니다.

Windows Server Containers - provide application isolation through process and namespace isolation technology. A Windows Server container shares a kernel with the container host and all containers running on the host.

Hyper-V Containers - expand on the isolation provided by Windows Server Containers by running each container in a highly optimized virtual machine. In this configuration the kernel of the container host is not shared with the Hyper-V Containers


간단히 정리하면 커널 수준까지의 격리를 원한다면 Hyper-V 컨테이너로 하면 되고, 사용자 모드의 격리만 하고 싶다면 Windows Containers를 사용하면 됩니다. 그 외에 알아두어야 할 용어라면 다음과 같은 정도가 있습니다.

Container Host: - Physical or Virtual computer system configured with the Windows Container feature.
 즉, 윈도우 PC에서 "Containers" 기능을 켜면 그것이 "Container Host"가 됩니다.

Container OS Image: - Containers are deployed from images. The container OS image is the first layer in potentially many image layers that make up a container. This image provides the operating system environment.
 쉽게 생각해서 VM 만들 때 최초 Clean OS가 담긴 VHDX 파일이라고 보면 됩니다.

Container Image: - A container image contains the base operating system, application, and all application dependencies needed to quickly deploy a container. 
 이후 Container OS Image에 기반한 응용 프로그램 및 실행환경을 담은 이미지 파일입니다.

Container Registry: - Container images are stored in a container registry, and can be downloaded on demand. 
 docker 이미지들이 담긴 저장소(repository)라고 보시면 됩니다. 우리가 잘 아는 docker 역시 저장소를 통해 다양한 Container 이미지들을 배포하고 있는데, 원한다면 사설 저장소도 구축해 운영하는 것이 가능합니다.

Dockerfile: - Dockerfiles are used to automate the creation of container images.
 이미지에 기반한 실행 인스턴스 생성을 자동화하는 설정 파일

Container: Container Image를 실행한 상태

참고로, 다음의 글을 읽어보시면 docker에 대한 이해를 좀 더 하실 수 있을 것입니다.

Docker 기본 사용법
; http://pyrasis.com/Docker/Docker-HOWTO

그리고, 이 글의 내용은 다음의 문서에서도 잘 나옵니다. ^^

Windows Containers on Windows 10
; https://github.com/Microsoft/Virtualization-Documentation/blob/live/virtualization/windowscontainers/quick_start/quick_start_windows_10.md




자, 그럼 ^^ 실습해 볼까요?

윈도우 10 (버전 1607이상)의 제어판에서 "Programs and Features"의 "Turn Windows features on or off" 링크를 누르면 다음과 같이 "Containers" 항목이 있는 것이 눈에 띕니다.

windows10_containers_1.png

이렇게 활성화해도 되고, 다음과 같이 PowerShell을 이용하셔도 됩니다.

Enable-WindowsOptionalFeature -Online -FeatureName containers -All

그리고, Hyper-V Containers 테스트를 위해 Hyper-V도 켜줍니다.

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

그다음, 재부팅 해주시고.

Restart-Computer -Force

마지막으로 docker를 설치해 줍니다. (사실 설치라기 보다는 실행 파일만 다운로드 받고 서비스 등록만 해주면 됩니다.)

Invoke-WebRequest "https://get.docker.com/builds/Windows/x86_64/docker-latest.zip" -OutFile "$env:TEMP\docker-latest.zip" -UseBasicParsing

Expand-Archive -Path "$env:TEMP\docker-latest.zip" -DestinationPath $env:ProgramFiles

[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Docker", [EnvironmentVariableTarget]::Machine)

&  $env:ProgramFiles\docker\dockerd.exe --register-service

Start-Service docker

압축해제된 파일은 "docker.exe", "dockerd.exe", "docker-proxy.exe"에 불과하고 용량도 15MB 정도입니다.

그런데, (2016년 8월 6일 기준) 위의 stable 버전을 다운로드 받으면 이후에 실습할 "docker run" 동작이 안됩니다. 대신 다음과 같이 개발 중인 버전을 다운로드 받아야 합니다.

Invoke-WebRequest https://master.dockerproject.org/windows/amd64/docker.exe -OutFile $env:ProgramFiles\docker\docker.exe
Invoke-WebRequest https://master.dockerproject.org/windows/amd64/dockerd.exe -OutFile $env:ProgramFiles\docker\dockerd.exe

이에 대해서는 다음의 글을 참고하세요.

Windows 10에서 Windows Containers의 docker run 실행 시 encountered an error during CreateContainer failed in Win32
; https://www.sysnet.pe.kr/2/0/11012

아무튼, ^^ 위의 과정을 마쳤으면 "서비스 관리자"에 "Docker Engine"이 서비스로 구동되고 있음을 확인할 수 있습니다.

이제 NanoServer ContainerImage를 다운로드 받겠습니다.

C:\Windows\system32>docker pull microsoft/nanoserver
Using default tag: latest
latest: Pulling from microsoft/nanoserver

cf62dbf6d334: Pull complete
Digest: sha256:e161c43c9695a20d0b7271e7339bb041026db548667d2d9ecc04e8dc6fba9bed
Status: Downloaded newer image for microsoft/nanoserver:latest

설치된 이미지 목록은 다음과 같이 확인합니다.

C:\Windows\system32>docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
microsoft/nanoserver   latest              3a703c6e97a2        7 weeks ago         969.8 MB

참고로, 삭제는 rmi 옵션으로 할 수 있습니다. (실습해야 하니 삭제하지 마세요. ^^)

C:\Windows\system32>docker rmi -f microsoft/nanoserver
Untagged: microsoft/nanoserver:latest
Untagged: microsoft/nanoserver@sha256:e161c43c9695a20d0b7271e7339bb041026db548667d2d9ecc04e8dc6fba9bed
Deleted: sha256:3a703c6e97a2e61046804e660009fa8eaaa60513d6f6a0ec68dae845c5b3929e
Deleted: sha256:58684737b3d187dfa028519839976bc5393e6c7d838a78f1d3468a4c7ba75ad6

이걸로 대충 준비는 끝입니다. 이제 여러분들은 격리된 공간에서 즉시 실행해 볼 수 있는 이미지가 준비된 것입니다. 일례로 다음과 같이 명령을 내릴 수 있습니다. (아래의 명령어 창은 반드시 '관리자 권한'으로 띄워야 합니다.)

C:\Windows\system32>docker run microsoft/nanoserver ipconfig

Windows IP Configuration


Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::9129:4559:c097:8839%4
   IPv4 Address. . . . . . . . . . . : 172.27.185.104
   Subnet Mask . . . . . . . . . . . : 255.240.0.0
   Default Gateway . . . . . . . . . : 172.16.0.1

위의 결과는, docker 내에서 microsoft/nanoserver 이미지를 구동시킨 후 인자로 함께 전달된 "ipconfig" 명령어를 그 환경 내에서 실행한 것입니다.

이 정도면 대충 docker가 어떤 것인지 감이 오시죠? ^^

ipconfig은 단순히 실행 후 종료되는 유형이지만 cmd.exe처럼 interactive한 프로그램을 실행하고 싶다면 다음과 같이 "-it" 인자와 함께 실행합니다. 그럼, 실행 후 곧바로 바뀐 환경 내에서 명령어를 실행하는 것이 가능합니다.

C:\Windows\system32>docker run -it microsoft/nanoserver cmd

화면으로 설명해 보면 다음과 같이 실행하는 경우,

windows10_containers_2.png

"-it" 옵션으로 인해 "cmd" 명령어가 실행되면서 같은 윈도우 창에서 다음과 같이 바뀝니다.

windows10_containers_3.png

이렇게 되면 nano 서버가 어떤지 구경해 볼 수 있습니다. ^^

C:\>dir
 Volume in drive C has no label.
 Volume Serial Number is 4864-3F22

 Directory of C:\

08/06/2016  12:58 AM    <DIR>          Program Files
08/06/2016  12:58 AM    <DIR>          Program Files (x86)
08/06/2016  12:58 AM    <DIR>          Users
08/06/2016  01:53 AM    <DIR>          Windows
               0 File(s)              0 bytes
               4 Dir(s)  21,209,399,296 bytes free

위의 경우 cmd.exe가 docker 내에서 실행 중인데요. 다른 명령어 창을 (관리자 권한으로) 열고 현재 docker에 의해 실행 중인 컨테이너 목록을 구하면 다음과 같은 결과를 얻습니다.

C:\Windows\system32>docker ps
CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS               NAMES
c394c80be213        microsoft/nanoserver   "cmd"               5 minutes ago       Up 4 minutes                            sharp_leavitt

cmd.exe 실행 환경을 종료하고 싶다면 command 창에서 exit 명령을 입력해서 종료할 수 있습니다.

docker가 재미있는 것은, 기본적인 "Container OS Image"를 기반으로 층층이 또 다른 "Container Image"들을 누적시켜 적용할 수 있다는 것입니다. 이에 대해서는 "WindowsServerCore"를 다룰 수 있는 "Windows Server 2016 TP5" 편에서 좀 더 다뤄보겠습니다. ^^

전반적으로 Windows 10에서는 이런 방법이 있다고만 알아두시고 실제 작업을 진행하는 것은 좀 미루는 것이 좋을 듯 합니다. 이 글을 쓰면서 실습하는 중에도 "docker run"을 해보면 간혹 가다가 실행이 안되고 그냥 오류로 빠지는 경우도 있었습니다. 물론 제가 실습을 안정화 버전(1.12.0)이 동작하지 않아서 개발 버전인 1.13.0-dev으로 했기 때문일 수도 있습니다. 아울러 아직 "Windows Server 2016"도 정식 버전이 나오지 않았기 때문에 향후로도 ContainerOSImage들은 숱하게 바뀔 수도 있을 것 같습니다.

참고로, Microsoft가 배포는 docker 이미지들은 다음과 같이 검색할 수 있습니다.

C:\WINDOWS\system32> docker search microsoft


NAME                                          DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
microsoft/aspnet                              ASP.NET is an open source server-side Web ...   464                   [OK]
microsoft/dotnet                              Official images for working with .NET Core...   207                   [OK]
mono                                          Mono is an open source implementation of M...   172       [OK]
microsoft/azure-cli                           Docker image for Microsoft Azure Command L...   61                    [OK]
microsoft/iis                                 Internet Information Services (IIS) instal...   25        
microsoft/mssql-server-2014-express-windows   Microsoft SQL Server 2014 Express installe...   23        
microsoft/nanoserver                          Nano Server base OS image for Windows cont...   11        
microsoft/windowsservercore                   Windows Server Core base OS image for Wind...   8         
microsoft/dotnet-preview                      Preview bits for microsoft/dotnet image         5                     [OK]
microsoft/oms                                 Monitor your containers using the Operatio...   5                     [OK]
microsoft/applicationinsights                 Application Insights for Docker helps you ...   3                     [OK]
microsoft/sample-nginx                        Nginx installed in Windows Server Core and...   2         
microsoft/sample-node                         Node installed in a Nano Server based cont...   2         
microsoft/sample-redis                        Redis installed in Windows Server Core and...   2         
microsoft/dotnet35                                                                            2         
microsoft/sqlite                              SQLite installed in a Windows Server Core ...   1         
microsoft/sample-httpd                        Apache httpd installed in Windows Server C...   1         
microsoft/sample-mongodb                                                                      1         
microsoft/sample-mysql                        MySQL installed in Windows Server Core and...   1         
microsoft/sample-dotnet                       .NET Core running in a Nano Server container    1         
microsoft/sample-golang                       Go Programming Language installed in Windo...   0         
microsoft/sample-python                       Python installed in Windows Server Core an...   0         
microsoft/sample-ruby                         Ruby installed in a Windows Server Core ba...   0         
microsoft/dotnet-nightly                      Preview bits of the .NET Core CLI               0                     [OK]
microsoft/sample-rails                        Ruby on Rails installed in Windows Server ...   0         

이건 docker에 업로드된 마이크로소프트의 이미지들이고, 여러분들도 docker와 유사한 repository를 만들어 사설 docker image 저장소를 만들 수 있습니다.




Hyper-V 컨테이너로 실행하는 것은 사실 간단합니다. 그냥 명령행에 "--isolation=hyperv" 인자만 주면 됩니다.

docker run --isolation=hyperv microsoft/nanoserver ipconfig

그러니까, 격리 수준만 차이가 날뿐 "Windows Containers"를 사용하든 "Hyper-V Containers"를 사용하든 개발자 입장에서는 크게 신경 쓸 필요가 없는 것입니다.




설치된 Image OS는 "C:\Users\All Users\docker" 폴더 하위에 위치합니다. "C:\Users\All Users\docker\image\windowsfilter" 폴더의 repositories.json을 보면 다음과 같이 확인할 수 있습니다.

{"Repositories":{"microsoft/nanoserver":{"microsoft/nanoserver:latest":"sha256:3a703c6e97a2e61046804e660009fa8eaaa60513d6f6a0ec68dae845c5b3929e","microsoft/nanoserver@sha256:e161c43c9695a20d0b7271e7339bb041026db548667d2d9ecc04e8dc6fba9bed":"sha256:3a703c6e97a2e61046804e660009fa8eaaa60513d6f6a0ec68dae845c5b3929e"}}}





Container OS Image를 설치하는 방법으로,

Windows Containers Documentation
; https://learn.microsoft.com/en-us/virtualization/windowscontainers/

위의 문서 목차에서 "Manage Windows Containers" / "Container Images"의 내용은 Install-ContainerImage 명령어로 소개하고 있습니다.

그런데, 이 명령은 Windows 10에서 실행하면 다음과 같은 오류를 내뱉습니다.

PS C:\Windows\system32> Install-ContainerImage -Name NanoServer

Install-ContainerOSImage : The term 'Install-ContainerOSImage' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\ContainerImage\0.6.4.0\ContainerImage.psm1:502 char:5
+     Install-ContainerOSImage -WimPath $Destination `
+     ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Install-ContainerOSImage:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Install-ContainerOSImage 명령어는 Windows Server 2016에서는 지원하는데, Windows 10에서는 지원되지 않습니다. (향후 지원될지는 모르겠지만.)

같은 문서의 "Container Quick Start" / "2 - Windows Server Quick Start" 문서는 OS Image 설치를 "docker pull"로 설명합니다. 그리고 그 명령어는 Windows 10에서도 사용할 수 있습니다.




docker 쪽 하위 폴더가 전통적인 260 길이 제한을 벗어나기 때문에 다루기가 좀 까다로울 수 있습니다. 따라서 아래의 내용에 따라,

How to enable paths longer than 260 characters in Windows 10
; http://betanews.com/2016/05/29/long-paths-windows-10/

gpedit.msc를 실행해 "Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem"의 "Enable NTFS long paths" 를 활성화하면 좋습니다.




마지막으로, "Mark Russinovich"의 멋진 구조 설명입니다. ^^

Containers: Docker, Windows and Trends
; https://azure.microsoft.com/ko-kr/blog/containers-docker-windows-and-trends/




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 7/3/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2016-10-07 01시04분
그새 또 많이 발전했군요. ^^

Run Linux and Windows Containers on Windows 10
; https://stefanscherer.github.io/run-linux-and-windows-containers-on-windows-10/

Windows 10에서 windowsservercore 컨테이너도 사용할 수 있다고 합니다.
정성태
2018-10-02 04시34분
간단하게 살펴 보는 Docker for Windows
; http://www.sysnet.pe.kr/2/0/11204

Announcing Removal of Foreign Layers from Windows Container Images
; https://techcommunity.microsoft.com/t5/containers/announcing-removal-of-foreign-layers-from-windows-container/ba-p/3846833
정성태
2019-09-26 09시34분
[채홍윤] 안녕하세요 도커 실습중에 문의드립니다.

dorker pull Microsoft/nanoserver 를 입력하면 해당 메시지가 나오는데 나노서버는 이제 다운 받을 수 없는건가요?
Error response from daemon: manifest for microsoft/nanoserver:latest not found: manifest unknown: manifest unknown
[guest]
2019-09-26 09시58분
이름이 바뀐 것 같습니다. 다음의 링크를 참고하세요.

Nano Server
; https://hub.docker.com/_/microsoft-windows-nanoserver
정성태

[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13600정성태4/18/2024233닷넷: 2242. C# - 관리 스레드와 비관리 스레드
13599정성태4/17/2024270닷넷: 2241. C# - WAV 파일의 PCM 사운드 재생(Windows Multimedia)파일 다운로드1
13598정성태4/16/2024281닷넷: 2240. C# - WAV 파일 포맷 + LIST 헤더파일 다운로드1
13597정성태4/15/2024357닷넷: 2239. C# - WAV 파일의 PCM 데이터 생성 및 출력파일 다운로드1
13596정성태4/14/2024699닷넷: 2238. C# - WAV 기본 파일 포맷파일 다운로드1
13595정성태4/13/2024824닷넷: 2237. C# - Audio 장치 열기 (Windows Multimedia, NAudio)파일 다운로드1
13594정성태4/12/2024998닷넷: 2236. C# - Audio 장치 열람 (Windows Multimedia, NAudio)파일 다운로드1
13593정성태4/8/20241048닷넷: 2235. MSBuild - AccelerateBuildsInVisualStudio 옵션
13592정성태4/2/20241202C/C++: 165. CLion으로 만든 Rust Win32 DLL을 C#과 연동
13591정성태4/2/20241164닷넷: 2234. C# - WPF 응용 프로그램에 Blazor App 통합파일 다운로드1
13590정성태3/31/20241071Linux: 70. Python - uwsgi 응용 프로그램이 k8s 환경에서 OOM 발생하는 문제
13589정성태3/29/20241138닷넷: 2233. C# - 프로세스 CPU 사용량을 나타내는 성능 카운터와 Win32 API파일 다운로드1
13588정성태3/28/20241191닷넷: 2232. C# - Unity + 닷넷 App(WinForms/WPF) 간의 Named Pipe 통신파일 다운로드1
13587정성태3/27/20241149오류 유형: 900. Windows Update 오류 - 8024402C, 80070643
13586정성태3/27/20241293Windows: 263. Windows - 복구 파티션(Recovery Partition) 용량을 늘리는 방법
13585정성태3/26/20241094Windows: 262. PerformanceCounter의 InstanceName에 pid를 추가한 "Process V2"
13584정성태3/26/20241046개발 환경 구성: 708. Unity3D - C# Windows Forms / WPF Application에 통합하는 방법파일 다운로드1
13583정성태3/25/20241149Windows: 261. CPU Utilization이 100% 넘는 경우를 성능 카운터로 확인하는 방법
13582정성태3/19/20241406Windows: 260. CPU 사용률을 나타내는 2가지 수치 - 사용량(Usage)과 활용률(Utilization)파일 다운로드1
13581정성태3/18/20241585개발 환경 구성: 707. 빌드한 Unity3D 프로그램을 C++ Windows Application에 통합하는 방법
13580정성태3/15/20241136닷넷: 2231. C# - ReceiveTimeout, SendTimeout이 적용되지 않는 Socket await 비동기 호출파일 다운로드1
13579정성태3/13/20241493오류 유형: 899. HTTP Error 500.32 - ANCM Failed to Load dll
13578정성태3/11/20241627닷넷: 2230. C# - 덮어쓰기 가능한 환형 큐 (Circular queue)파일 다운로드1
13577정성태3/9/20241865닷넷: 2229. C# - 닷넷을 위한 난독화 도구 소개 (예: ConfuserEx)
13576정성태3/8/20241543닷넷: 2228. .NET Profiler - IMetaDataEmit2::DefineMethodSpec 사용법
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...