Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 476. DockerDesktopVM의 파일 시스템 접근 [링크 복사], [링크+제목 복사]
조회: 9923
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 7개 있습니다.)

DockerDesktopVM의 파일 시스템 접근

혹시나 DockerDesktopVM에 접근하는 방법이 있지 않을까 싶어 검색해 봤더니,

How to SSH into the Docker VM (MobyLinuxVM) on Windows
; https://blog.jongallant.com/2017/11/ssh-into-docker-vm-windows/

아쉽게도 SSH 접속은 안 되는 듯싶고, 대신 DockerDesktopVM의 파일 시스템을 조회하는 수준에서 가능합니다. 이것을 docker스러운 방법으로 해결하고 있는데, 즉 다음의 명령어로 컨테이너 하나를 실행시키면,

c:\temp> docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm -v /:/host alpine /bin/sh
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
c9b1b535fdd9: Pull complete
Digest: sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d
Status: Downloaded newer image for alpine:latest
/ #

내부의 shell 환경에서 "host" 폴더가 제공되는데,

/ # ls -l
total 56
drwxr-xr-x    2 root     root          4096 Jan 16 21:52 bin
drwxr-xr-x   10 root     root          3300 Mar  6 18:34 dev
drwxr-xr-x    1 root     root          4096 Mar  6 18:34 etc
drwxr-xr-x    2 root     root          4096 Jan 16 21:52 home
drwxr-xr-x    1 root     root           380 Mar  6 16:13 host
drwxr-xr-x    5 root     root          4096 Jan 16 21:52 lib
drwxr-xr-x    5 root     root          4096 Jan 16 21:52 media
drwxr-xr-x    2 root     root          4096 Jan 16 21:52 mnt
drwxr-xr-x    2 root     root          4096 Jan 16 21:52 opt
dr-xr-xr-x  126 root     root             0 Mar  7  2020 proc
drwx------    1 root     root          4096 Mar  6 18:34 root
drwxr-xr-x    2 root     root          4096 Jan 16 21:52 run
drwxr-xr-x    2 root     root          4096 Jan 16 21:52 sbin
drwxr-xr-x    2 root     root          4096 Jan 16 21:52 srv
dr-xr-xr-x   13 root     root             0 Mar  7  2020 sys
drwxrwxrwt    2 root     root          4096 Jan 16 21:52 tmp
drwxr-xr-x    7 root     root          4096 Jan 16 21:52 usr
drwxr-xr-x   12 root     root          4096 Jan 16 21:52 var

그 내용이 DockerDesktopVM 내부의 파일 시스템이 됩니다.

/ # ls host -l
total 8167
drwxr-xr-x    2 root     root         14336 Feb  5 08:09 bin
drwxr-xr-x   11 root     root          3340 Mar  7  2020 dev
drwxr-xr-x    1 root     root           200 Mar  7 09:47 etc
drwxr-xr-x    2 root     root          2048 Feb  5 08:09 home
drwxr-xr-x    1 root     root            60 Mar  7 09:47 lib
drwxr-xr-x    5 root     root          2048 Feb  5 08:09 media
drwxr-xr-x    2 root     root          2048 Feb  5 08:09 mnt
drwxr-xr-x    1 root     root            80 Mar  7 09:47 opt
dr-xr-xr-x  130 root     root             0 Mar  7  2020 proc
drwx------    1 root     root            60 Mar  7 12:57 root
drwxr-xr-x    1 root     root           180 Mar  7 09:47 run
drwxr-xr-x    2 root     root         30720 Feb  5 08:09 sbin
-rwxr-xr-x    1 root     root       8308778 Feb  9 15:48 sendtohost
drwxr-xr-x    2 root     root          2048 Feb  5 08:09 srv
dr-xr-xr-x   13 root     root             0 Mar  7  2020 sys
drwxrwxrwt    1 root     root            40 Mar  7 13:18 tmp
drwxr-xr-x    1 root     root            80 Feb  5 08:09 usr
drwxr-xr-x    1 root     root            60 Feb  5 08:10 var




정말 그런지 실습을 해볼까요? ^^ 아래의 글에서,

docker - SQL Server 2019 컨테이너 실행
; https://www.sysnet.pe.kr/2/0/12173

다음과 같은 식으로 볼륨 공유를 했을 때,

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=test_1234" -v sqlvolume:/var/opt/mssql -p 1433:1433 --name sql1 -d mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04

sqlvolume 디렉터리가 DockerDesktopVM 호스트의 어딘가에 저장이 되어 있을 텐데, 이를 다음과 같이 찾아낼 수 있습니다.

/ # find / -name sqlvolume
/host/var/lib/docker/volumes/sqlvolume

/ # ls /host/var/lib/docker/volumes/sqlvolume/_data/data -l
total 97668
-rw-r-----    1 10001    root           256 Mar  7 12:33 Entropy.bin
-rw-r-----    1 10001    root       4653056 Mar  7 13:12 master.mdf
-rw-r-----    1 10001    root       2097152 Mar  7 13:23 mastlog.ldf
-rw-r-----    1 10001    root       8388608 Mar  7 13:12 model.mdf
-rw-r-----    1 10001    root      14024704 Mar  7 12:33 model_msdbdata.mdf
-rw-r-----    1 10001    root        524288 Mar  7 12:33 model_msdblog.ldf
-rw-r-----    1 10001    root        524288 Mar  7 12:33 model_replicatedmaster.ldf
-rw-r-----    1 10001    root       4653056 Mar  7 12:33 model_replicatedmaster.mdf
-rw-r-----    1 10001    root       8388608 Mar  7 13:12 modellog.ldf
-rw-r-----    1 10001    root      14024704 Mar  7 13:12 msdbdata.mdf
-rw-r-----    1 10001    root        786432 Mar  7 13:12 msdblog.ldf
-rw-r-----    1 10001    root       8388608 Mar  7 13:12 tempdb.mdf
-rw-r-----    1 10001    root       8388608 Mar  7 13:12 tempdb2.ndf
-rw-r-----    1 10001    root       8388608 Mar  7 13:17 templog.ldf




알아본 김에, DockerDesktopVM 환경에 대해 더 파헤쳐 보겠습니다. 우선, "Docker Desktop"을 설치하면 HOSTS 파일에 DNS 이름이 등록됩니다.

# Added by Docker Desktop
192.168.100.50 host.docker.internal
192.168.100.50 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

사실, 저렇게 등록된 IP는 "Docker Desktop"이 설치된 컴퓨터의 IP에 불과합니다. 오히려 알아내고 싶은 IP는 Docker subnet(기본값은 "192.168.65.0/28") 상에서의 DockerDesktopVM에 대한 IP일 텐데요. 다행히 "Docker Desktop"은 DockerDesktopVM이 호스팅하는 container 내부에도 "host.docker.internal" DNS를 등록하고 있으며 그것에 매핑된 IP 주소가 subnet 상의 DockerDesktopVM의 주소가 됩니다. 그래서 아무 container나 하나 실행하고 거기서 다음과 같이 ping을 해보면 알 수 있습니다.

/ # ping host.docker.internal -c 1
PING host.docker.internal (192.168.65.2): 56 data bytes
64 bytes from 192.168.65.2: seq=0 ttl=38 time=8.639 ms

--- host.docker.internal ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 8.639/8.639/8.639 ms

("Docker Desktop" 환경에서 별다른 설정이 없다면 대개의 경우 DockerDesktopVM의 주소는 192.168.65.2입니다.)




그렇다면, 당연히 dockerd가 사용하는 daemon.json 파일도 있겠군요.

/ # find / -name daemon.json
/host/run/config/docker/daemon.json

/run 디렉터리에 있는 것으로 보아 임시 파일 역할만 할 뿐 사실상 설정 변경은 할 수 없습니다. 아마도, 윈도우에 설치된 "Docker Desktop"이 관리하는 "%USERPROFILE%\.docker\daemon.json" 파일이 기반이고, 런타임 시에 DockerDesktopVM 측의 /host/run/config/docker/daemon.json 파일로 제공하는 듯합니다.

참고로, DockerDesktopVM에 설치된 docker, dockerd는 모두 "/host/usr/local/bin/" 디렉터리에 있습니다.




"How to SSH into the Docker VM (MobyLinuxVM) on Windows" 글에 보면, alpine container를 ubuntu-docker-client 내에서 실행하는 것을 볼 수 있습니다.

C:\temp> docker run --privileged -it -v /var/run/docker.sock:/var/run/docker.sock jongallant/ubuntu-docker-client
root@546a9d760774:/# docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm -v /:/host alpine /bin/sh
/ #

이렇게 하는 경우 host 디렉터리 하위에 Hyper-V를 호스팅하는 윈도우 시스템의 드라이브까지 매핑이 된 것을 볼 수 있습니다.

/ # ls host -l
total 8167
lrwxrwxrwx    1 root     root            11 Mar  6 16:13 C -> /host_mnt/c
lrwxrwxrwx    1 root     root            11 Mar  6 16:13 D -> /host_mnt/d
lrwxrwxrwx    1 root     root            11 Mar  6 16:13 E -> /host_mnt/e
drwxr-xr-x    2 root     root         14336 Feb  5 08:09 bin
lrwxrwxrwx    1 root     root            11 Mar  6 16:13 c -> /host_mnt/c
lrwxrwxrwx    1 root     root            11 Mar  6 16:13 d -> /host_mnt/d
drwxr-xr-x   11 root     root          3340 Mar  7  2020 dev
lrwxrwxrwx    1 root     root            11 Mar  6 16:13 e -> /host_mnt/e
drwxr-xr-x    1 root     root           200 Mar  6 16:13 etc
drwxr-xr-x    2 root     root          2048 Feb  5 08:09 home
drwxr-xr-x    5 root     root           100 Mar  6 16:13 host_mnt
drwxr-xr-x    1 root     root            60 Mar  6 16:13 lib
drwxr-xr-x    5 root     root          2048 Feb  5 08:09 media
drwxr-xr-x    2 root     root          2048 Feb  5 08:09 mnt
drwxr-xr-x    1 root     root            80 Mar  6 16:13 opt
dr-xr-xr-x  126 root     root             0 Mar  7  2020 proc
drwx------    1 root     root            60 Mar  6 16:46 root
drwxr-xr-x    1 root     root           180 Mar  6 16:13 run
drwxr-xr-x    2 root     root         30720 Feb  5 08:09 sbin
-rwxr-xr-x    1 root     root       8308778 Feb  9 15:48 sendtohost
drwxr-xr-x    2 root     root          2048 Feb  5 08:09 srv
dr-xr-xr-x   13 root     root             0 Mar  7  2020 sys
drwxrwxrwt    1 root     root            40 Mar  6 18:34 tmp
drwxr-xr-x    1 root     root            80 Feb  5 08:09 usr
drwxr-xr-x    1 root     root            60 Feb  5 08:10 var




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 3/8/2020]

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

비밀번호

댓글 작성자
 



2020-03-12 10시07분
Docker Container 내부 소켓 상태 확인 - nsenter와 netstat
; https://aidanbae.github.io/code/docker/docker-netstat/

docker inspect -f '{{.State.Pid}}' {container_id or name}
sudo nsenter -t 5645 -n netstat
정성태
2020-08-07 10시56분
docker run --restart=always -v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock --name ${IMGNAME} -v ${VOLUMENAME}:/testdir -p 15001:80 -d ${IMGNAME}:latest
정성태
2021-03-26 01시06분
alpine 내에서의 package 관리자

/ # apk update
/ # apk upgrade
/ # apk add net-tools
/ # apk add curl
정성태

... 16  17  18  19  20  21  22  23  24  25  26  27  [28]  29  30  ...
NoWriterDateCnt.TitleFile(s)
12921정성태1/14/20225626개발 환경 구성: 624. Docker Desktop에서 별도 서버에 설치한 docker registry에 이미지 올리는 방법
12920정성태1/14/20226395오류 유형: 786. Camtasia - An error occurred with the camera: Failed to Add Video Sampler.
12919정성태1/13/20226223Windows: 199. Host Network Service (HNS)에 의해서 점유되는 포트
12918정성태1/13/20226412Linux: 47. WSL - shell script에서 설정한 환경 변수가 스크립트 실행 후 반영되지 않는 문제
12917정성태1/12/20225658오류 유형: 785. C# - The type or namespace name '...' could not be found (are you missing a using directive or an assembly reference?)
12916정성태1/12/20225389오류 유형: 784. TFS - One or more source control bindings for this solution are not valid and are listed below.
12915정성태1/11/20225670오류 유형: 783. Visual Studio - We didn't find any interpreters
12914정성태1/11/20227571VS.NET IDE: 172. 비주얼 스튜디오 2022의 파이선 개발 환경 지원
12913정성태1/11/20228109.NET Framework: 1133. C# - byte * (바이트 포인터)를 FileStream으로 쓰는 방법 [1]
12912정성태1/11/20228742개발 환경 구성: 623. ffmpeg.exe를 사용해 비디오 파일의 이미지를 PGM(Portable Gray Map) 파일 포맷으로 출력하는 방법 [1]
12911정성태1/11/20226067VS.NET IDE: 171. 비주얼 스튜디오 - 더 이상 만들 수 없는 "ASP.NET Core 3.1 Web Application (.NET Framework)" 프로젝트
12910정성태1/10/20226550제니퍼 .NET: 30. 제니퍼 닷넷 적용 사례 (8) - CPU high와 DB 쿼리 성능에 문제가 함께 있는 사이트
12909정성태1/10/20227949오류 유형: 782. Visual Studio 2022 설치 시 "Couldn't install Microsoft.VisualCpp.Redist.14.Latest"
12908정성태1/10/20225786.NET Framework: 1132. C# - ref/out 매개변수의 IL 코드 처리
12907정성태1/9/20226248오류 유형: 781. (youtube-dl.exe) 실행 시 "This app can't run on your PC" / "Access is denied." 오류 발생
12906정성태1/9/20226856.NET Framework: 1131. C# - 네임스페이스까지 동일한 타입을 2개의 DLL에서 제공하는 경우 충돌을 우회하는 방법 [1]파일 다운로드1
12905정성태1/8/20226517오류 유형: 780. Could not load file or assembly 'Microsoft.VisualStudio.TextTemplating.VSHost.15.0, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
12904정성태1/8/20228552개발 환경 구성: 623. Visual Studio 2022 빌드 환경을 위한 github Actions 설정 [1]
12903정성태1/7/20227147.NET Framework: 1130. C# - ELEMENT_TYPE_INTERNAL 유형의 사용 예
12902정성태1/7/20227179오류 유형: 779. SQL 서버 로그인 에러 - provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.
12901정성태1/5/20227273오류 유형: 778. C# - .NET 5+에서 warning CA1416: This call site is reachable on all platforms. '...' is only supported on: 'windows' 경고 발생
12900정성태1/5/20228920개발 환경 구성: 622. vcpkg로 ffmpeg를 빌드하는 경우 생성될 구성 요소 제어하는 방법
12899정성태1/3/20228404개발 환경 구성: 621. windbg에서 python 스크립트 실행하는 방법 - pykd (2)
12898정성태1/2/20228956.NET Framework: 1129. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 비디오 인코딩 예제(encode_video.c) [1]파일 다운로드1
12897정성태1/2/20227839.NET Framework: 1128. C# - 화면 캡처한 이미지를 ffmpeg(FFmpeg.AutoGen)로 동영상 처리 [4]파일 다운로드1
12896정성태1/1/202210705.NET Framework: 1127. C# - FFmpeg.AutoGen 라이브러리를 이용한 기본 프로젝트 구성파일 다운로드1
... 16  17  18  19  20  21  22  23  24  25  26  27  [28]  29  30  ...