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

윈도우 환경에서의 dockerd.exe("Docker Engine" 서비스)가 Linux의 것과 다른 점

기본적으로 "docker.exe" 클라이언트는 "//./pipe/docker_engine" 경로로 연결을 시도합니다.

만약 "Docker Desktop for Windows" 버전이 설치되어 있다면 "com.docker.proxy.exe"가 "//./pipe/docker_engine" 이름의 파이프를 열어 "docker.exe"의 요청을 중계합니다. 이때 Docker Desktop이 1) 리눅스 컨테이너 모드로 동작 중이라면 "//./pipe/docker_engine_linux"로 전달하고, 2) 윈도우 컨테이너 모드로 동작 중이라면 "dockerd.exe"가 열고 있는 "//./pipe/docker_engine_windows"로 전달하기 때문에 docker.exe는 "Docker Desktop" 프로그램이 설정한 모드의 컨테이너 호스트와 통신을 하게 됩니다.

참고로, "Docker Desktop for Windows"가 설치된 경우 com.docker.proxy.exe 프로세스나 dockerd.exe 서비스는 "Docker Desktop"이 관리합니다.

반면, DockerMsftProvider로 설치해 Windows Containers만 동작 중인 컴퓨터라면 ("com.docker.proxy.exe" 파일이 없으므로) "dockerd.exe"가 직접 제공하는 "//./pipe/docker_engine" named pipe를 통해 docker.exe가 통신을 하게 됩니다.

그런데, dockerd.exe가 어떻게 알고 "//./pipe/docker_engine" 또는 "//./pipe/docker_engine_windows"로 named pipe 이름을 정하는 걸까요? 일단, dockerd.exe는 기본적으로 "//./pipe/docker_engine" 이름으로 named pipe을 엽니다. 하지만 "Docker Desktop"이 관여하는 경우에는 dockerd.exe (Docker Engine) 서비스의 실행 경로가 다음과 같이 바뀌게 되고,

"C:\Program Files\Docker\Docker\resources\dockerd.exe" --run-service --service-name docker -G "testad\testuser" --config-file C:\ProgramData\DockerDesktop\tmp-d4w\daemon.json


지정된 "C:\ProgramData\DockerDesktop\tmp-d4w\daemon.json" 파일을 열어 보면 수수께끼가 풀립니다.

{
  "registry-mirrors": [],
  "insecure-registries": [],
  "debug": true,
  "experimental": false,
  "hosts": [
    "npipe:////./pipe/docker_engine_windows"
  ]
}




이렇게 named pipe 통신이 기본이지만, docker.exe 실행 시 "-H" 옵션을 주는 경우 TCP 연결을 하는 것도 가능합니다.

// localhost(127.0.0.1) 서버로 TCP 연결

c:\temp> docker -H tcp://127.0.0.1:2375 images

물론, docker 호스트 측에서는 해당 TCP 연결을 받을 수 있는 포트를 열어야 하는데, 이와 관련해 localhost 내에서의 접근에 한해 TCP 연결을 허용하는 옵션이 제공됩니다.

docker_remote_1.png

Expose daemon on tcp://localhsot:2375 without TLS
Exposing daemon on TCP without TLS helps legacy clients connect to the daemon. It also makes yourself vulnerable to remote code execution attacks. Use with caution.


(유의할 것은, 위의 옵션을 선택한 다음 우측 하단의 "Apply & Restart" 버튼을 눌러도 효력이 없습니다. 이것을 적용하려면 "Docker Desktop"의 tray icon으로부터 "Restart..." 메뉴를 선택해야 합니다.)

그럼 해당 TCP Port는 "127.0.0.1"로 바인딩돼 com.docker.proxy.exe가 열고 있습니다.

C:\temp> netstat -ano | findstr 2375
  TCP    127.0.0.1:2375         0.0.0.0:0              LISTENING       5920

[com.docker.proxy.exe 명령어]

"com.docker.proxy.exe"  -dockerExe "C:\Program Files\Docker\Docker\resources\bin\docker.exe" -exposeTcp=localhost:2375 -host-names host.docker.internal,docker.for.win.host.internal,docker.for.win.localhost -gateway-names gateway.docker.internal,docker.for.win.gateway.internal,docker.for.win.http.internal -vm-names vm.docker.internal,docker-for-desktop,docker-desktop,kubernetes.docker.internal -host-ip 192.168.65.2 -gateway-ip 192.168.65.1 -vm-ip 192.168.65.3 -pki "C:\ProgramData\DockerDesktop\pki" -inject-hosts=True"

좀 더 들어가 보면, "Expose daemon on tcp://localhsot:2375 without TLS" 옵션은 결국 "%USERPROFILE%\AppData\Roaming\Docker\settings.json" 파일에 다음과 같이 저장되므로,

{
  "settingsVersion": 5,
  "autoStart": true,
  "checkForUpdates": true,
  "analyticsEnabled": false,
  "displayedWelcomeWhale": true,
    ...[생략]...
  "useWindowsContainers": false,
  "swarmFederationExplicitlyLoggedOut": false,
  "activeOrganizationName": null,
  "exposeDockerAPIOnTCP2375": true,
  "lifecycleTimeoutSeconds": 600,
  "customWslDistroDir": null,
  "wslEngineEnabled": false,
  "integratedWslDistros": null,
  "networkCIDR": "10.0.75.0/24",
  "diskPath": null
}

원한다면 settings.json 파일을 직접 편집해도 무방합니다.




"Expose daemon on tcp://localhsot:2375 without TLS" 옵션은 같은 localhost 내에서의 접근만 허용하는 반면, 외부에서도 접속할 수 있도록 설정하는 옵션은 따로 있습니다.

여기서 재미있는 것은, "Docker Desktop for Windows"의 Linux 컨테이너 모드와 Windows 컨테이너 모드에 대해 전자의 경우에는 해당 옵션을 바꿀 수 없도록 해놨다는 것입니다. (우회 방법: "Docker Desktop for Windows"의 "Linux Container" 모드를 위한 tcp 바인딩 추가) 실제로 Linux 컨테이너 모드의 경우 "%USERPROFILE%\.docker\daemon.json" 설정 파일을 사용하는데, 이곳에 TCP 바인딩 옵션을 다음과 같이 추가하면,

{
  "registry-mirrors": [],
  "insecure-registries": [],
  "debug": true,
  "experimental": false,
  "hosts": [
    "tcp://0.0.0.0:2375",
    "npipe://"
  ]
}

"Docker Desktop for Windows"을 재시작할 때 BackendException 예외가 발생합니다.

Docker.Core.Backend.BackendException:
Failed to start
   at Docker.Core.Pipe.NamedPipeClient.<TrySendAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Docker.Core.Pipe.NamedPipeClient.Send(String action, Object[] parameters)
   at Docker.Actions.DoRestartVM(Settings previousSettings)
   at Docker.Actions.<>c__DisplayClass34_0.<RestartVM>b__0()
   at Docker.ApiServices.TaskQueuing.TaskQueue.<>c__DisplayClass18_0.<.ctor>b__1()

  Docker.Core.DockerException:
  Failed to start
     at Docker.Backend.ContainerEngine.Linux.DoStart(Settings settings, String daemonOptions, Credential credential)
     at Docker.Backend.ContainerEngine.Linux.Restart(Settings settings, String daemonOptions, Credential credential)
     at Docker.Backend.BackendNamedPipeServer.<Run>b__8_3(Object[] args)
     at Docker.Core.Pipe.NamedPipeServer.<>c__DisplayClass9_0.<Register>b__0(Object[] parameters)
     at Docker.Core.Pipe.NamedPipeServer.RunAction(String action, Object[] parameters)

사실 이게 맞는 정책입니다. 왜냐하면 지난 글에서도 설명했지만 "Docker Desktop for Windows"는 운영체제에 로그인한 사용자 계정에 종속되어 있기 때문에 (위에서 설명한 json 파일들의 경로도 %USERPROFILE% 하위였고) 서비스 형식으로 포트를 열고 있는 것이 더 혼란스러울 수 있습니다.

대신, Windows Containers는 (로그인 계정에 종속되지 않은) 완벽한 서비스 형식이기 때문에 TCP 바인딩을 허용합니다. 따라서, dockerd.exe가 사용하는 설정 파일(별도로 바꾸지 않았다면 C:\ProgramData\docker\config\daemon.json)을 편집해,

{
  "registry-mirrors": [],
  "insecure-registries": [],
  "debug": true,
  "experimental": false,
  "hosts": [
    "tcp://0.0.0.0:2375",
    "npipe://"
  ]
}

("npipe://"라고 하면 기본적으로 "//./pipe/docker_engine" 이름으로 named pipe를 엽니다.)

서비스를 재시작하면 "0.0.0.0:2375"로 바인딩을 하고,

C:\WINDOWS\system32> netstat -ano | findstr 2375
  TCP    0.0.0.0:2375           0.0.0.0:0              LISTENING       10360
  TCP    [::]:2375              [::]:0                 LISTENING       10360

다른 컴퓨터에서 TCP 연결로 docker 관련 명령어를 수행할 수 있습니다.

C:\Windows\System32> docker -H tcp://192.168.100.50:2375 info
Client:
 Debug Mode: false
 Plugins:
  cluster: Manage Docker clusters (Docker Inc., v1.2.0)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 ...[생략]...




한 가지 주의할 것은, DockerMsftProvider로 설치한 Windows Containers 환경은 상관없지만, 2가지 컨테이너 모드를 지원하는 "Docker Desktop for Windows"라면 named pipe 바인딩과 tcp 바인딩의 결과가 다를 수 있다는 점입니다.

예를 들어, "Docker Desktop"의 모드를 "Linux Container"로 한 상태에서 dockerd.exe가 TCP 바인딩을 추가한 상태라면 "docker.exe info"의 명령어 수행 결과가 각각 다음과 같이 다르게 됩니다.

// Windows Containers만을 바라보는 dockerd.exe가 제공하는 tcp 바인딩

c:\temp> docker -H tcp://192.168.100.50:2375 info
Client:
 Debug Mode: false

Server:
 Containers: 1
  Running: 1
  Paused: 0
  Stopped: 0
 Images: 1
 Server Version: 17.05.0-ce
 Storage Driver: windowsfilter
 ...[생략]...
 Operating System: Windows Server 2019 Datacenter
 OSType: windows
 ...[생략]...

// Docker Desktop이 현재 Linux Container 모드로 설정되어, 그것과 매핑이 된 named pipe 바인딩

c:\temp> docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 2
Server Version: 19.03.5
Storage Driver: overlay2
 ...[생략]...
Operating System: Docker Desktop
OSType: linux
 ...[생략]...

다시 말해, "Docker Desktop"의 com.docker.proxy.exe가 열어둔 "//./pipe/docker_engine" 파이프는 "//./pipe/docker_engine_linux"로 중계돼 Linux Container에 대한 정보를 제공하는 반면, dockerd.exe가 제공하는 tcp 바인딩은 해당 서비스 자체가 언제나 Windows Containers만을 바라보고 있기 때문입니다.




윈도우에서 제공하는 dockerd.exe에는 몇 가지 더 복잡한 문제들이 있습니다.

DockerMsftProvider로 설치한 docker 환경에서는 dockerd.exe가 NT 서비스에 등록되어 "Local SYSTEM" 권한으로, 게다가 열고 있는 Named Pipe에 대한 권한 조정을 하지 않았기 때문에 "//./pipe/docker_engine" 파이프에 대해 일반 사용자 권한으로 접근하면 다음과 같은 식의 오류가 발생합니다.

C:\temp> docker info
Client:
Debug Mode: false
Plugins:
cluster: Manage Docker clusters (Docker Inc., v1.2.0)

Server:
ERROR: error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/info: open //./pipe/docker_engine: Access is denied. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running. errors pretty printing info


물론, "Docker Desktop for Windows"가 설치된 경우에는 ("//./pipe/docker_engine" 파이프를 열고 있는) com.docker.proxy.exe가 현재 로그인 한 사용자 계정으로 실행되고 따라서 Named Pipe 권한도 조정될 필요가 없으므로 관리자 권한이 없어도 docker.exe 클라이언트 명령어가 정상적으로 동작합니다.

위와 마찬가지의 이유로 인해 (DockerMsftProvider로 설치한 docker 환경에서는) Kitematic 프로그램도 일반 사용자 권한으로 실행하면 이런 오류 메시지를 보게 됩니다.

Setup Initialization

We couldn't find a native setup - Click the VirtualBox button to use VirtualBox instead or Retry to check again

하지만, 설령 관리자 모드로 실행한다고 해도 Kitematic의 경우 이후 이미지로부터 컨테이너를 실행하거나 하는 등의 작업들이 (Linux 컨테이너를 대상으로는 잘 되었지만) 윈도우 컨테이너를 대상으로는 동작하지 않는 문제가 있습니다. 예를 들어, 아래는 Windows Containers로부터 nano server 이미지 조회가 된 것인데,

kitematic_wincon_1.png

실제로 "CREATE"를 시켜 컨테이너로 실행하려고 하면 이런 오류가 발생합니다.

kitematic_wincon_2.png

(HTTP code 404) no such image - no such image: mcr.microsoft.com/windows:1809-amd64: No such image: mcr.microsoft.com/windows:1809-amd64




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/26/2023]

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

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13422정성태10/5/20233204닷넷: 2148. C# - async 유무에 따른 awaitable 메서드의 병렬 및 예외 처리
13421정성태10/4/20233242닷넷: 2147. C# - 비동기 메서드의 async 예약어 유무에 따른 차이
13420정성태9/26/20235322스크립트: 57. 파이썬 - UnboundLocalError: cannot access local variable '...' where it is not associated with a value
13419정성태9/25/20233092스크립트: 56. 파이썬 - RuntimeError: dictionary changed size during iteration
13418정성태9/25/20233758닷넷: 2146. C# - ConcurrentDictionary 자료 구조의 동기화 방식
13417정성태9/19/20233336닷넷: 2145. C# - 제네릭의 형식 매개변수에 속한 (매개변수를 가진) 생성자를 호출하는 방법
13416정성태9/19/20233152오류 유형: 877. redis-py - MISCONF Redis is configured to save RDB snapshots, ...
13415정성태9/18/20233639닷넷: 2144. C# 12 - 컬렉션 식(Collection Expressions)
13414정성태9/16/20233390디버깅 기술: 193. Windbg - ThreadStatic 필드 값을 조사하는 방법
13413정성태9/14/20233581닷넷: 2143. C# - 시스템 Time Zone 변경 시 이벤트 알림을 받는 방법
13412정성태9/14/20236853닷넷: 2142. C# 12 - 인라인 배열(Inline Arrays) [1]
13411정성태9/12/20233363Windows: 252. 권한 상승 전/후 따로 관리되는 공유 네트워크 드라이브 정보
13410정성태9/11/20234863닷넷: 2141. C# 12 - Interceptor (컴파일 시에 메서드 호출 재작성) [1]
13409정성태9/8/20233721닷넷: 2140. C# - Win32 API를 이용한 모니터 전원 끄기
13408정성태9/5/20233714Windows: 251. 임의로 만든 EXE 파일을 포함한 ZIP 파일의 압축을 해제할 때 Windows Defender에 의해 삭제되는 경우
13407정성태9/4/20233473닷넷: 2139. C# - ParallelEnumerable을 이용한 IEnumerable에 대한 병렬 처리
13406정성태9/4/20233426VS.NET IDE: 186. Visual Studio Community 버전의 라이선스
13405정성태9/3/20233841닷넷: 2138. C# - async 메서드 호출 원칙
13404정성태8/29/20233363오류 유형: 876. Windows - 키보드의 등호(=, Equals sign) 키가 눌리지 않는 경우
13403정성태8/21/20233188오류 유형: 875. The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
13402정성태8/20/20233249닷넷: 2137. ILSpy의 nuget 라이브러리 버전 - ICSharpCode.Decompiler
13401정성태8/19/20233525닷넷: 2136. .NET 5+ 환경에서 P/Invoke의 성능을 높이기 위한 SuppressGCTransition 특성 [1]
13400정성태8/10/20233351오류 유형: 874. 파이썬 - pymssql을 윈도우 환경에서 설치 불가
13399정성태8/9/20233373닷넷: 2135. C# - 지역 변수로 이해하는 메서드 매개변수의 값/참조 전달
13398정성태8/3/20234134스크립트: 55. 파이썬 - pyodbc를 이용한 SQL Server 연결 사용법
13397정성태7/23/20233639닷넷: 2134. C# - 문자열 연결 시 string.Create를 이용한 GC 할당 최소화
1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...