소리소문 없이... 사랑도 명예도 이름도 남김 없이...
DexCore.net

Docker

[Docker] 윈도우 WSL 설정을 통한 도커 데스크탑 데이터 저장 위치 접근 방법

탑~! 2025. 2. 19. 11:18

1. 윈도우 WSL 설정을 통한 도커 데스크탑 데이터 저장 위치 접근 방법

(1) WSL 다른 배포판(Ubuntu)에 마운트

① Windows 터미널에서 WSL 다른 배포판(Ubuntu_20.04.6_LTS)에 vhdx 이미지 파일을 마운트

# wsl -d <working system> --mount --vhd <path to image>\<image name>.vhdx --bare
PS C:\Users\islove8587> wsl -d Ubuntu_20.04.6_LTS --mount --vhd E:\WSL\Docker\ext4.vhdx --bare
작업을 완료했습니다.

② Ubuntu_20.04.6_LTS 배포판 root 계정으로 접속

PS C:\Users\islove8587> wsl -d Ubuntu_20.04.6_LTS -u root
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.146.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun Jun  9 15:59:17 KST 2024

  System load:  0.9                 Processes:             43
  Usage of /:   0.2% of 1006.85GB   Users logged in:       0
  Memory usage: 1%                  IPv4 address for eth0: 172.18.144.236
  Swap usage:   0%

 * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
   just raised the bar for easy, resilient and secure K8s cluster deployment.

   https://ubuntu.com/engage/secure-kubernetes-at-the-edge

Expanded Security Maintenance for Applications is not enabled.

51 updates can be applied immediately.
To see these additional updates run: apt list --upgradable

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status



This message is shown once a day. To disable it please create the
/root/.hushlogin file.
root@DESKTOP-4SUN7F6:/mnt/c/Users/islove8587# cd ~
root@DESKTOP-4SUN7F6:~#

③ 마운트 할 디렉터리 생성

root@DESKTOP-4SUN7F6:~# mkdir /docker-desktop-data-mnt

마운트 지점에 장치를 마운트 후 해당 디렉터리로 이동

root@DESKTOP-4SUN7F6:~# mount /dev/sdc /docker-desktop-data-mnt
root@DESKTOP-4SUN7F6:~# cd /docker-desktop-data-mnt

⑤ 마운트 한 디렉터리 내용 보기

root@DESKTOP-4SUN7F6:/docker-desktop-data-mnt# ls -al
total 3320
drwxr-xr-x 17 root root    4096 Jun  9 15:35 .
drwxr-xr-x 21 root root    4096 Jun  9 16:05 ..
drwxr-xr-x  3 root root    4096 May  2 15:52 .docker
drwxr-xr-x  2 root root    4096 May  2 15:52 bin
drwxr-xr-x 11 root root    4096 May  2 15:52 data
drwxr-xr-x  4 root root    4096 Apr 19  2017 dev
drwxr-xr-x  2 root root    4096 Jun  9 15:35 etc
-rwxr-xr-x  1 root root       0 Jun  9 15:35 init
drwxr-xr-x  3 root root    4096 May 23 16:55 isocache
drwxr-xr-x  3 root root    4096 May  2 15:52 lib
drwx------  2 root root   16384 May  2 15:52 lost+found
drwxr-xr-x  7 root root    4096 May  2 15:52 mnt
drwxr-xr-x  2 root root    4096 Apr 19  2017 proc
drwxr-xr-x  2 root root    4096 May  2 15:52 run
drwxr-xr-x  2 root root    4096 May  2 15:52 sbin
drwxr-xr-x  2 root root    4096 Apr 19  2017 sys
drwxrwxrwt  3 root root    4096 May  2 15:52 tmp
drwxr-xr-x  3 root root    4096 May  2 15:52 usr
-rwxr-xr-x  1 root root 3316560 Mar 20 22:47 wsl-keepalive
root@DESKTOP-4SUN7F6:/docker-desktop-data-mnt#

Docker root 디렉터리 구조 보기

root@DESKTOP-4SUN7F6:/docker-desktop-data-mnt# ls -al data/docker
total 60
drwx--x--- 12 root root  4096 Jun  8 15:05 .
drwxr-xr-x 11 root root  4096 May  2 15:52 ..
drwx--x--x  5 root root  4096 Jun  1 14:17 buildkit
drwx--x---  7 root root  4096 Jun  8 17:31 containers
-rw-------  1 root root    36 May  2 15:52 engine-id
drwx------  3 root root  4096 May  2 15:52 image
drwxr-x---  3 root root  4096 May  2 15:52 network
drwx--x--- 95 root root 12288 Jun  8 17:31 overlay2
drwx------  4 root root  4096 May  2 15:52 plugins
drwx------  2 root root  4096 Jun  8 15:05 runtimes
drwx------  2 root root  4096 May  2 15:52 swarm
drwx------  2 root root  4096 Jun  8 17:34 tmp
drwx-----x 11 root root  4096 Jun  8 15:05 volumes
root@DESKTOP-4SUN7F6:/docker-desktop-data-mnt#

⑦ docker-desktop-data-mnt 디렉터리 마운트 해제 후 삭제

root@DESKTOP-4SUN7F6:/docker-desktop-data-mnt# cd ~
root@DESKTOP-4SUN7F6:~# umount /docker-desktop-data-mnt
root@DESKTOP-4SUN7F6:~# rm -rf /docker-desktop-data-mnt
root@DESKTOP-4SUN7F6:~#

⑧ Windows 터미널로 돌아가 이미지를 마운트 해제

root@DESKTOP-4SUN7F6:~# exit logout
PS C:\Users\islove8587> wsl --unmount \\?\E:\WSL\Docker\ext4.vhdx 작업을 완료했습니다.
PS C:\Users\islove8587>

(2) 도커 데스크탑 데이터를 마운트 한 컨테이너(ubuntu)를 생성

① /var/lib/docker 폴더를 마운트 하는 ubuntu 컨테이너를 생성하여, shell 환경으로 실행

PS C:\Users\islove8587> docker run --name ubuntu -v/:/data -it ubuntu /bin/bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
00d679a470c4: Pull complete
Digest: sha256:e3f92abc0967a6c19d0dfa2d55838833e947b9d74edbcb0113e48535ad4be12a
Status: Downloaded newer image for ubuntu:latest
root@b7d48f10f7d0:/#

② root(/) 디렉터리, 즉 최상위 디렉터리 위치를 마운트 한 /data 변경

root@b7d48f10f7d0:/# chroot /data
sh-5.2#

Info

chroot란 Change Root Directiory의 줄임말로 현재 실행 중인 프로세스와 자녀 프로세스의 루트 디렉터리를 변경하는 작업입니다.

Docker root 디렉터리 구조 보기

sh-5.2# ls -la /var/lib/docker
total 60
drwx--x---  12 root root  4096 Jun  8 06:05 .
drwxr-xr-x  11 root root  4096 May  2 06:52 ..
drwx--x--x   5 root root  4096 Jun  1 05:17 buildkit
drwx--x---   9 root root  4096 Jun  8 07:21 containers
-rw-------   1 root root    36 May  2 06:52 engine-id
drwx------   3 root root  4096 May  2 06:52 image
drwxr-x---   3 root root  4096 May  2 06:52 network
drwx--x--- 106 root root 12288 Jun  8 07:21 overlay2
drwx------   4 root root  4096 May  2 06:52 plugins
drwx------   2 root root  4096 Jun  8 06:05 runtimes
drwx------   2 root root  4096 May  2 06:52 swarm
drwx------   2 root root  4096 Jun  8 07:19 tmp
drwx-----x  11 root root  4096 Jun  8 06:05 volumes
sh-5.2#

④ Windows 터미널로 돌아가서, 생성한 ubuntu 컨테이너 삭제 처리

sh-5.2# exit
exit
root@8cb301cf9ef1:/# exit
exit

What's next?
  Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug ubuntu
  Learn more at https://docs.docker.com/go/debug-cli/
PS C:\Users\islove8587> docker stop ubuntu     # ubuntu 컨테이너 중지
ubuntu
PS C:\Users\islove8587> docker rm ubuntu       # ubuntu 컨테이너 삭제
ubuntu
PS C:\Users\islove8587> docker rmi ubuntu      # ubuntu 컨테이너 이미지 삭제
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:e3f92abc0967a6c19d0dfa2d55838833e947b9d74edbcb0113e48535ad4be12a
Deleted: sha256:17c0145030df106e60e5d99149d69810db23b869ff0d3c9d236279a5a7bbb6b3
Deleted: sha256:42d3f8788282c6e48bac7236609753b240db353465dc55cb77c21f2391720dd9
PS C:\Users\islove8587>

 

 

출처 : https://blog.naver.com/islove8587/223473752762

728x90
반응형